forked from labex-labs/python-cheatsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogTitleHeader.vue
More file actions
61 lines (55 loc) · 1.56 KB
/
BlogTitleHeader.vue
File metadata and controls
61 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script setup lang="ts">
interface Frontmatter {
date: string
updated: string
tags: string
socialImage?: string
}
const props = defineProps<{
frontmatter: Frontmatter
title: string
}>()
const reader = useReaderStore()
const tags = props.frontmatter.tags?.split(', ')
const getImageSrc = (imagePath?: string): string => {
if (!imagePath) return ''
if (imagePath.startsWith('http')) return imagePath
const basePath = import.meta.env.BASE_URL || '/pythoncheatsheet/'
return basePath.endsWith('/') ? `${basePath}${imagePath.slice(1)}` : `${basePath}${imagePath}`
}
</script>
<template>
<div>
<div class="flex items-center">
<span class="font-display text-sm font-medium text-primary-500">
Posted on {{ frontmatter.date }}
</span>
<span class="ml-2 text-slate-400">·</span>
<span
v-if="frontmatter.updated"
class="font-display text-sm text-slate-400 sm:ml-2"
>
Updated on {{ frontmatter.updated }}
</span>
</div>
<h1 :class="tags && !reader.isActive ? 'mb-0' : ''">{{ title }}</h1>
<div
v-if="tags && !reader.isActive"
class="mb-10 mt-3 flex flex-wrap gap-3 text-xs text-slate-50 dark:text-white"
>
<span
v-for="tag in tags"
:key="tag"
class="rounded bg-primary-500 px-1.5 py-1 dark:bg-primary-600"
>
#{{ tag }}
</span>
</div>
<img
v-if="frontmatter.socialImage"
:src="getImageSrc(frontmatter.socialImage)"
:alt="`Image for ${title}`"
class="w-full rounded-lg my-4"
/>
</div>
</template>