|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useNotionBlock, defineNotionProps } from "@/lib/blockable" |
| 3 | +import { computed } from "vue" |
| 4 | +import { useTimeAgo } from "@vueuse/core" |
| 5 | +
|
| 6 | +const props = defineProps({ ...defineNotionProps }) |
| 7 | +//@ts-ignore |
| 8 | +const { format, block, hasPageLinkOptions, pageLinkProps } = useNotionBlock(props) |
| 9 | +
|
| 10 | +const properties = computed(() => format.value.drive_properties) |
| 11 | +
|
| 12 | +const constructThumbnail = (src?: string) => { |
| 13 | + if (!src) return |
| 14 | + const q = new URLSearchParams({ |
| 15 | + table: "block", |
| 16 | + id: block.value.value.id, |
| 17 | + cache: "v2", |
| 18 | + }) |
| 19 | + return "https://www.notion.so/image/" + encodeURIComponent(src) + "?" + q |
| 20 | +} |
| 21 | +const constructDomain = (src?: string) => { |
| 22 | + if (!src) return |
| 23 | + return new URL(src).hostname |
| 24 | +} |
| 25 | +</script> |
| 26 | + |
| 27 | +<script lang="ts"> |
| 28 | +export default { |
| 29 | + name: "NotionGoogleDrive", |
| 30 | +} |
| 31 | +</script> |
| 32 | + |
| 33 | +<template> |
| 34 | + <div class="notion-google-drive"> |
| 35 | + <a rel="noopener noreferrer" target="_blank" :href="properties.url" class="notion-google-drive-link"> |
| 36 | + <div class="notion-google-drive-preview"> |
| 37 | + <img :src="constructThumbnail(properties.thumbnail)" :alt="properties.title" /> |
| 38 | + </div> |
| 39 | + |
| 40 | + <div className="notion-google-drive-body"> |
| 41 | + <div className="notion-google-drive-body-title"> |
| 42 | + {{ properties.title }} |
| 43 | + </div> |
| 44 | + |
| 45 | + <div className="notion-google-drive-body-modified-time"> |
| 46 | + Last modified |
| 47 | + {{ properties.user_name ? `by ${properties.user_name} ` : "" }} |
| 48 | + {{ useTimeAgo(properties.modified_time).value }} |
| 49 | + </div> |
| 50 | + |
| 51 | + <div className="notion-google-drive-body-source"> |
| 52 | + <div |
| 53 | + className="notion-google-drive-body-source-icon" |
| 54 | + :style="{ backgroundImage: 'url(' + properties.icon + ')' }" |
| 55 | + /> |
| 56 | + <div className="notion-google-drive-body-source-domain">{{ constructDomain(properties.url) }}</div> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </a> |
| 60 | + </div> |
| 61 | +</template> |
0 commit comments