@frontfactory/vitepress-theme 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +260 -0
- package/config.d.ts +6 -0
- package/config.js +54 -0
- package/dist/style.css +1709 -0
- package/package.json +84 -0
- package/src/components/FfBackToTop.vue +50 -0
- package/src/components/FfBanner.vue +74 -0
- package/src/components/FfDocMeta.vue +112 -0
- package/src/components/FfFeature.vue +44 -0
- package/src/components/FfFooter.vue +40 -0
- package/src/components/FfHero.vue +171 -0
- package/src/composables/options.ts +48 -0
- package/src/content/Api.vue +32 -0
- package/src/content/Card.vue +31 -0
- package/src/content/CardGrid.vue +9 -0
- package/src/content/Kbd.vue +3 -0
- package/src/content/Steps.vue +5 -0
- package/src/index.ts +52 -0
- package/src/internal.ts +10 -0
- package/src/layout/FfLayout.vue +41 -0
- package/src/styles/_base.scss +121 -0
- package/src/styles/_blocks.scss +103 -0
- package/src/styles/_code.scss +163 -0
- package/src/styles/_content.scss +374 -0
- package/src/styles/_doc.scss +416 -0
- package/src/styles/_home.scss +429 -0
- package/src/styles/_motion.scss +231 -0
- package/src/styles/_nav.scss +224 -0
- package/src/styles/_sidebar.scss +127 -0
- package/src/styles/_theme.scss +8 -0
- package/src/styles/_tokens.scss +235 -0
- package/src/styles/index.scss +19 -0
- package/src/types.ts +96 -0
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@frontfactory/vitepress-theme",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Editorial VitePress theme — hairline rules, numbered sections and monospaced metadata.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "sass --no-source-map --pkg-importer=node --load-path=node_modules src/styles/index.scss dist/style.css",
|
|
8
|
+
"dev": "npm run build -- --watch",
|
|
9
|
+
"dev:playground": "npm run build && vitepress dev playground",
|
|
10
|
+
"build:playground": "npm run build && vitepress build playground",
|
|
11
|
+
"typecheck": "vue-tsc --noEmit",
|
|
12
|
+
"prepare": "husky",
|
|
13
|
+
"prepack": "npm run build",
|
|
14
|
+
"release": "semantic-release"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"main": "./src/index.ts",
|
|
20
|
+
"module": "./src/index.ts",
|
|
21
|
+
"types": "./src/index.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./src/index.ts",
|
|
25
|
+
"default": "./src/index.ts"
|
|
26
|
+
},
|
|
27
|
+
"./config": {
|
|
28
|
+
"types": "./config.d.ts",
|
|
29
|
+
"default": "./config.js"
|
|
30
|
+
},
|
|
31
|
+
"./style.css": "./dist/style.css",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@commitlint/cli": "^20.4.2",
|
|
36
|
+
"@commitlint/config-conventional": "^20.4.2",
|
|
37
|
+
"@magnesium/theme": "^5.2.2",
|
|
38
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
39
|
+
"@semantic-release/git": "^10.0.1",
|
|
40
|
+
"@semantic-release/github": "^12.0.9",
|
|
41
|
+
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
42
|
+
"husky": "^9.1.7",
|
|
43
|
+
"sass": "^1.100.0",
|
|
44
|
+
"semantic-release": "^25.0.9",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vitepress": "^2.0.0-alpha.20",
|
|
47
|
+
"vue": "^3.5.34",
|
|
48
|
+
"vue-tsc": "^3.2.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"vitepress": "^2.0.0-alpha.20",
|
|
52
|
+
"vue": "^3.5.0"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"vitepress",
|
|
56
|
+
"vitepress-theme",
|
|
57
|
+
"theme",
|
|
58
|
+
"documentation",
|
|
59
|
+
"editorial"
|
|
60
|
+
],
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"homepage": "https://github.com/front-factory/vitepress-theme",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/front-factory/vitepress-theme/issues"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/front-factory/vitepress-theme.git"
|
|
69
|
+
},
|
|
70
|
+
"author": "Front Factory",
|
|
71
|
+
"sideEffects": [
|
|
72
|
+
"*.css"
|
|
73
|
+
],
|
|
74
|
+
"files": [
|
|
75
|
+
"src",
|
|
76
|
+
"dist",
|
|
77
|
+
"config.js",
|
|
78
|
+
"config.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public",
|
|
82
|
+
"provenance": true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
3
|
+
import { useData } from 'vitepress'
|
|
4
|
+
import { useLabels, useThemeOptions } from '../composables/options'
|
|
5
|
+
|
|
6
|
+
const { theme } = useData()
|
|
7
|
+
const options = useThemeOptions()
|
|
8
|
+
const labels = useLabels()
|
|
9
|
+
|
|
10
|
+
// The visible text is the accessible name; the tooltip reuses the default theme's own option,
|
|
11
|
+
// so a site that already localised its mobile return-to-top link gets this one for free.
|
|
12
|
+
const title = computed(() => theme.value.returnToTopLabel ?? 'Return to top')
|
|
13
|
+
|
|
14
|
+
const enabled = computed(() => options.value.backToTop !== false)
|
|
15
|
+
|
|
16
|
+
const visible = ref(false)
|
|
17
|
+
|
|
18
|
+
function onScroll() {
|
|
19
|
+
visible.value = window.scrollY > window.innerHeight
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toTop() {
|
|
23
|
+
window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onMounted(() => {
|
|
27
|
+
onScroll()
|
|
28
|
+
window.addEventListener('scroll', onScroll, { passive: true })
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
onUnmounted(() => window.removeEventListener('scroll', onScroll))
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<ClientOnly>
|
|
36
|
+
<button
|
|
37
|
+
v-if="enabled"
|
|
38
|
+
type="button"
|
|
39
|
+
class="ff-to-top ff-label"
|
|
40
|
+
:class="{ 'is-visible': visible }"
|
|
41
|
+
:tabindex="visible ? 0 : -1"
|
|
42
|
+
:aria-hidden="!visible"
|
|
43
|
+
:title="title"
|
|
44
|
+
@click="toTop"
|
|
45
|
+
>
|
|
46
|
+
<span aria-hidden="true">↑</span>
|
|
47
|
+
<span>{{ labels.backToTop }}</span>
|
|
48
|
+
</button>
|
|
49
|
+
</ClientOnly>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
3
|
+
import { useLabels, useThemeOptions } from '../composables/options'
|
|
4
|
+
|
|
5
|
+
const options = useThemeOptions()
|
|
6
|
+
const labels = useLabels()
|
|
7
|
+
const banner = computed(() => options.value.banner)
|
|
8
|
+
|
|
9
|
+
const el = ref<HTMLElement>()
|
|
10
|
+
let observer: ResizeObserver | undefined
|
|
11
|
+
|
|
12
|
+
// The class is set on <html> by an inline script injected in the head, so a dismissed banner never
|
|
13
|
+
// paints. See transformHead() in config.js.
|
|
14
|
+
const DISMISSED = 'ff-banner-dismissed'
|
|
15
|
+
|
|
16
|
+
function height() {
|
|
17
|
+
const root = document.documentElement
|
|
18
|
+
|
|
19
|
+
if (!banner.value || root.classList.contains(DISMISSED)) {
|
|
20
|
+
root.style.removeProperty('--vp-layout-top-height')
|
|
21
|
+
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
root.style.setProperty('--vp-layout-top-height', `${el.value?.offsetHeight ?? 0}px`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function dismiss() {
|
|
29
|
+
if (!banner.value) return
|
|
30
|
+
|
|
31
|
+
localStorage.setItem(`ff-banner-${banner.value.id}`, 'dismissed')
|
|
32
|
+
document.documentElement.classList.add(DISMISSED)
|
|
33
|
+
height()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
onMounted(() => {
|
|
37
|
+
height()
|
|
38
|
+
|
|
39
|
+
if (el.value) {
|
|
40
|
+
observer = new ResizeObserver(height)
|
|
41
|
+
observer.observe(el.value)
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
onUnmounted(() => {
|
|
46
|
+
observer?.disconnect()
|
|
47
|
+
document.documentElement.style.removeProperty('--vp-layout-top-height')
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div v-if="banner" ref="el" class="ff-banner">
|
|
53
|
+
<component
|
|
54
|
+
:is="banner.link ? 'a' : 'div'"
|
|
55
|
+
class="ff-banner-body"
|
|
56
|
+
:href="banner.link"
|
|
57
|
+
>
|
|
58
|
+
<span class="ff-banner-text" v-html="banner.text" />
|
|
59
|
+
<span v-if="banner.link" class="ff-banner-cta">
|
|
60
|
+
{{ banner.linkText ?? 'Read more' }}
|
|
61
|
+
<span aria-hidden="true">→</span>
|
|
62
|
+
</span>
|
|
63
|
+
</component>
|
|
64
|
+
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
class="ff-banner-close"
|
|
68
|
+
:aria-label="labels.bannerDismiss"
|
|
69
|
+
@click="dismiss"
|
|
70
|
+
>
|
|
71
|
+
×
|
|
72
|
+
</button>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { useData } from 'vitepress'
|
|
4
|
+
import { useLayout } from '../internal'
|
|
5
|
+
import { format, useLabels, useThemeOptions } from '../composables/options'
|
|
6
|
+
import type { DefaultTheme } from 'vitepress/theme'
|
|
7
|
+
|
|
8
|
+
const { page, frontmatter, lang } = useData()
|
|
9
|
+
const { sidebarGroups } = useLayout()
|
|
10
|
+
const options = useThemeOptions()
|
|
11
|
+
const labels = useLabels()
|
|
12
|
+
|
|
13
|
+
const meta = computed(() => {
|
|
14
|
+
if (options.value.meta === false || frontmatter.value.docMeta === false) return null
|
|
15
|
+
|
|
16
|
+
return options.value.meta ?? {}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// --------------------------------------------------------------------------------------------- //
|
|
20
|
+
// Section, read from the sidebar the site already declares
|
|
21
|
+
//
|
|
22
|
+
// The groups come from the default theme's own resolver, so multi-sidebar configs, per-group
|
|
23
|
+
// `base` prefixes and `sidebar: false` in the frontmatter are all already accounted for.
|
|
24
|
+
// --------------------------------------------------------------------------------------------- //
|
|
25
|
+
|
|
26
|
+
function normalize(path: string) {
|
|
27
|
+
return path
|
|
28
|
+
.replace(/^\//, '')
|
|
29
|
+
.replace(/(index)?\.(md|html)$/, '')
|
|
30
|
+
.replace(/\/$/, '')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function contains(items: DefaultTheme.SidebarItem[], path: string): boolean {
|
|
34
|
+
return items.some(
|
|
35
|
+
(item) =>
|
|
36
|
+
(item.link && normalize(item.link) === path) || contains(item.items ?? [], path)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const section = computed(() => {
|
|
41
|
+
if (!meta.value || meta.value.section === false) return null
|
|
42
|
+
if (frontmatter.value.section) return String(frontmatter.value.section)
|
|
43
|
+
|
|
44
|
+
const path = normalize(page.value.relativePath)
|
|
45
|
+
|
|
46
|
+
return sidebarGroups.value.find((group) => contains(group.items ?? [], path))?.text ?? null
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// --------------------------------------------------------------------------------------------- //
|
|
50
|
+
// Reading time, measured on the rendered page
|
|
51
|
+
// --------------------------------------------------------------------------------------------- //
|
|
52
|
+
|
|
53
|
+
const words = ref(0)
|
|
54
|
+
|
|
55
|
+
function measure() {
|
|
56
|
+
words.value =
|
|
57
|
+
document.querySelector('.vp-doc')?.textContent?.trim().split(/\s+/).filter(Boolean)
|
|
58
|
+
.length ?? 0
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onMounted(() => nextTick(measure))
|
|
62
|
+
watch(() => page.value.relativePath, () => nextTick(measure))
|
|
63
|
+
|
|
64
|
+
const minutes = computed(() => {
|
|
65
|
+
if (!meta.value || meta.value.readingTime === false || !words.value) return null
|
|
66
|
+
|
|
67
|
+
return Math.max(1, Math.round(words.value / (meta.value.wordsPerMinute ?? 200)))
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// --------------------------------------------------------------------------------------------- //
|
|
71
|
+
// Last updated
|
|
72
|
+
// --------------------------------------------------------------------------------------------- //
|
|
73
|
+
|
|
74
|
+
const units: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
75
|
+
['year', 31536000000],
|
|
76
|
+
['month', 2592000000],
|
|
77
|
+
['week', 604800000],
|
|
78
|
+
['day', 86400000],
|
|
79
|
+
['hour', 3600000],
|
|
80
|
+
['minute', 60000]
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
const updated = computed(() => {
|
|
84
|
+
if (!meta.value || meta.value.lastUpdated === false || !page.value.lastUpdated) return null
|
|
85
|
+
|
|
86
|
+
const elapsed = page.value.lastUpdated - Date.now()
|
|
87
|
+
const relative = new Intl.RelativeTimeFormat(lang.value, { numeric: 'auto' })
|
|
88
|
+
|
|
89
|
+
for (const [unit, ms] of units) {
|
|
90
|
+
if (Math.abs(elapsed) >= ms) return relative.format(Math.round(elapsed / ms), unit)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return relative.format(0, 'minute')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const hidden = computed(() => !meta.value || frontmatter.value.layout === 'home')
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<template>
|
|
100
|
+
<div v-if="!hidden" class="ff-doc-meta ff-label">
|
|
101
|
+
<span v-if="section" class="ff-doc-meta-item">{{ section }}</span>
|
|
102
|
+
|
|
103
|
+
<ClientOnly>
|
|
104
|
+
<span v-if="minutes" class="ff-doc-meta-item">
|
|
105
|
+
{{ format(labels.readingTime, minutes) }}
|
|
106
|
+
</span>
|
|
107
|
+
<span v-if="updated" class="ff-doc-meta-item">
|
|
108
|
+
{{ format(labels.lastUpdated, updated) }}
|
|
109
|
+
</span>
|
|
110
|
+
</ClientOnly>
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { VPImage, VPLink } from '../internal'
|
|
3
|
+
import type { DefaultTheme } from 'vitepress/theme'
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
icon?: DefaultTheme.FeatureIcon
|
|
7
|
+
title: string
|
|
8
|
+
details?: string | string[]
|
|
9
|
+
link?: string
|
|
10
|
+
linkText?: string
|
|
11
|
+
rel?: string
|
|
12
|
+
target?: string
|
|
13
|
+
}>()
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<VPLink
|
|
18
|
+
class="VPFeature ff-feature"
|
|
19
|
+
:href="link"
|
|
20
|
+
:rel="rel"
|
|
21
|
+
:target="target"
|
|
22
|
+
:no-icon="true"
|
|
23
|
+
:tag="link ? 'a' : 'div'"
|
|
24
|
+
>
|
|
25
|
+
<span class="ff-feature-index" aria-hidden="true" />
|
|
26
|
+
|
|
27
|
+
<div v-if="typeof icon === 'object'" class="ff-feature-icon">
|
|
28
|
+
<VPImage :image="icon" :alt="icon.alt" :height="icon.height || 28" :width="icon.width || 28" />
|
|
29
|
+
</div>
|
|
30
|
+
<div v-else-if="icon" class="ff-feature-icon" v-html="icon" />
|
|
31
|
+
|
|
32
|
+
<h2 class="ff-feature-title" v-html="title" />
|
|
33
|
+
|
|
34
|
+
<ul v-if="Array.isArray(details)" class="ff-feature-details">
|
|
35
|
+
<li v-for="item in details" :key="item" v-html="item" />
|
|
36
|
+
</ul>
|
|
37
|
+
<p v-else-if="details" class="ff-feature-details" v-html="details" />
|
|
38
|
+
|
|
39
|
+
<span v-if="linkText" class="ff-feature-link ff-label">
|
|
40
|
+
{{ linkText }}
|
|
41
|
+
<span aria-hidden="true">→</span>
|
|
42
|
+
</span>
|
|
43
|
+
</VPLink>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { useData } from 'vitepress'
|
|
4
|
+
import { useLayout, VPLink } from '../internal'
|
|
5
|
+
import { useThemeOptions } from '../composables/options'
|
|
6
|
+
|
|
7
|
+
const { theme, frontmatter } = useData()
|
|
8
|
+
const { hasSidebar } = useLayout()
|
|
9
|
+
const options = useThemeOptions()
|
|
10
|
+
|
|
11
|
+
const columns = computed(() => options.value.footerColumns ?? [])
|
|
12
|
+
const visible = computed(
|
|
13
|
+
() => (theme.value.footer || columns.value.length) && frontmatter.value.footer !== false
|
|
14
|
+
)
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<footer v-if="visible" class="VPFooter ff-footer" :class="{ 'has-sidebar': hasSidebar }">
|
|
19
|
+
<div class="ff-footer-container">
|
|
20
|
+
<div v-if="columns.length" class="ff-footer-columns">
|
|
21
|
+
<div v-for="column in columns" :key="column.title" class="ff-footer-column">
|
|
22
|
+
<p class="ff-label">{{ column.title }}</p>
|
|
23
|
+
|
|
24
|
+
<ul>
|
|
25
|
+
<li v-for="item in column.items" :key="item.link">
|
|
26
|
+
<VPLink :href="item.link" :rel="item.rel" :target="item.target">
|
|
27
|
+
{{ item.text }}
|
|
28
|
+
</VPLink>
|
|
29
|
+
</li>
|
|
30
|
+
</ul>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<div v-if="theme.footer" class="ff-footer-legal">
|
|
35
|
+
<p v-if="theme.footer.message" class="message" v-html="theme.footer.message" />
|
|
36
|
+
<p v-if="theme.footer.copyright" class="copyright" v-html="theme.footer.copyright" />
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</footer>
|
|
40
|
+
</template>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Comment, computed, Fragment, ref, Text, useSlots, type VNode } from 'vue'
|
|
3
|
+
import { useData } from 'vitepress'
|
|
4
|
+
import { VPImage } from '../internal'
|
|
5
|
+
import { format, useLabels } from '../composables/options'
|
|
6
|
+
import type { HeroExtras, HeroMetaItem } from '../types'
|
|
7
|
+
import type { DefaultTheme } from 'vitepress/theme'
|
|
8
|
+
|
|
9
|
+
export interface HeroAction {
|
|
10
|
+
theme?: 'brand' | 'alt'
|
|
11
|
+
text: string
|
|
12
|
+
link: string
|
|
13
|
+
target?: string
|
|
14
|
+
rel?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
name?: string
|
|
19
|
+
text?: string
|
|
20
|
+
tagline?: string
|
|
21
|
+
image?: DefaultTheme.ThemeableImage
|
|
22
|
+
actions?: HeroAction[]
|
|
23
|
+
}>()
|
|
24
|
+
|
|
25
|
+
const { frontmatter } = useData()
|
|
26
|
+
const labels = useLabels()
|
|
27
|
+
const slots = useSlots()
|
|
28
|
+
|
|
29
|
+
// Two additions to the standard home frontmatter, both optional:
|
|
30
|
+
//
|
|
31
|
+
// hero.command the install line, printed in a panel beside the headline
|
|
32
|
+
// hero.meta a colophon strip under the hero: [{ label, value }, …]
|
|
33
|
+
const hero = computed<HeroExtras>(() => frontmatter.value.hero ?? {})
|
|
34
|
+
const command = computed<string | undefined>(() => hero.value.command)
|
|
35
|
+
const meta = computed<HeroMetaItem[]>(() => hero.value.meta ?? [])
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The home layout always declares the `home-hero-image` slot, so its presence says nothing about
|
|
39
|
+
* whether the site filled it. Rendering it and looking at what comes back does — an unfilled slot
|
|
40
|
+
* yields nothing but empty fragments and comment placeholders.
|
|
41
|
+
*/
|
|
42
|
+
function filled(nodes?: VNode[]): boolean {
|
|
43
|
+
return !!nodes?.some((node) => {
|
|
44
|
+
if (node.type === Comment) return false
|
|
45
|
+
if (node.type === Text) return String(node.children).trim() !== ''
|
|
46
|
+
if (node.type === Fragment) {
|
|
47
|
+
return Array.isArray(node.children) && filled(node.children as VNode[])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return true
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Called from the template rather than cached in a computed: the slot has to be rendered where its
|
|
55
|
+
// dependencies are tracked, and it changes with the page.
|
|
56
|
+
function hasImage() {
|
|
57
|
+
return !!props.image || filled(slots['home-hero-image']?.())
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The second column carries the image when there is one, and the starting point otherwise. The
|
|
61
|
+
// actions only move over there when they have a panel to sit in.
|
|
62
|
+
function hasPanel() {
|
|
63
|
+
return !hasImage() && !!command.value
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const copied = ref(false)
|
|
67
|
+
|
|
68
|
+
async function copy() {
|
|
69
|
+
if (!command.value) return
|
|
70
|
+
|
|
71
|
+
await navigator.clipboard.writeText(command.value)
|
|
72
|
+
copied.value = true
|
|
73
|
+
setTimeout(() => (copied.value = false), 2000)
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<div
|
|
79
|
+
class="VPHero ff-hero"
|
|
80
|
+
:class="{ 'has-image': hasImage(), 'has-panel': hasPanel() }"
|
|
81
|
+
>
|
|
82
|
+
<span class="ff-hero-glow" aria-hidden="true" />
|
|
83
|
+
<span class="ff-hero-glow ff-hero-glow-far" aria-hidden="true" />
|
|
84
|
+
|
|
85
|
+
<div class="ff-hero-container">
|
|
86
|
+
<div class="ff-hero-main">
|
|
87
|
+
<slot name="home-hero-info-before" />
|
|
88
|
+
|
|
89
|
+
<slot name="home-hero-info">
|
|
90
|
+
<p v-if="name" class="ff-hero-kicker ff-label">
|
|
91
|
+
<span class="ff-hero-mark" aria-hidden="true" />
|
|
92
|
+
<span v-html="name" />
|
|
93
|
+
</p>
|
|
94
|
+
|
|
95
|
+
<h1 v-if="text" class="ff-hero-title ff-display" v-html="text" />
|
|
96
|
+
|
|
97
|
+
<p v-if="tagline" class="ff-hero-tagline" v-html="tagline" />
|
|
98
|
+
</slot>
|
|
99
|
+
|
|
100
|
+
<slot name="home-hero-info-after" />
|
|
101
|
+
|
|
102
|
+
<div v-if="actions?.length && !hasPanel()" class="ff-hero-actions">
|
|
103
|
+
<slot name="home-hero-actions-before-actions" />
|
|
104
|
+
|
|
105
|
+
<a
|
|
106
|
+
v-for="action in actions"
|
|
107
|
+
:key="action.link"
|
|
108
|
+
class="ff-btn"
|
|
109
|
+
:class="`ff-btn-${action.theme ?? 'brand'}`"
|
|
110
|
+
:href="action.link"
|
|
111
|
+
:target="action.target"
|
|
112
|
+
:rel="action.rel"
|
|
113
|
+
>
|
|
114
|
+
{{ action.text }}
|
|
115
|
+
</a>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<slot name="home-hero-actions-after" />
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div v-if="hasImage()" class="ff-hero-image">
|
|
122
|
+
<slot name="home-hero-image">
|
|
123
|
+
<VPImage v-if="image" class="ff-hero-image-src" :image="image" />
|
|
124
|
+
</slot>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<aside v-else-if="hasPanel()" class="ff-hero-panel">
|
|
128
|
+
<p class="ff-hero-panel-label ff-label">{{ labels.heroInstall }}</p>
|
|
129
|
+
|
|
130
|
+
<div class="ff-hero-command">
|
|
131
|
+
<code>
|
|
132
|
+
<span class="ff-hero-prompt" aria-hidden="true">$</span>
|
|
133
|
+
{{ command }}
|
|
134
|
+
</code>
|
|
135
|
+
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
class="ff-hero-copy ff-label"
|
|
139
|
+
:aria-label="format(labels.heroCopyLabel, command ?? '')"
|
|
140
|
+
@click="copy"
|
|
141
|
+
>
|
|
142
|
+
{{ copied ? labels.heroCopied : labels.heroCopy }}
|
|
143
|
+
</button>
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<div v-if="actions?.length" class="ff-hero-actions">
|
|
147
|
+
<slot name="home-hero-actions-before-actions" />
|
|
148
|
+
|
|
149
|
+
<a
|
|
150
|
+
v-for="action in actions"
|
|
151
|
+
:key="action.link"
|
|
152
|
+
class="ff-btn"
|
|
153
|
+
:class="`ff-btn-${action.theme ?? 'brand'}`"
|
|
154
|
+
:href="action.link"
|
|
155
|
+
:target="action.target"
|
|
156
|
+
:rel="action.rel"
|
|
157
|
+
>
|
|
158
|
+
{{ action.text }}
|
|
159
|
+
</a>
|
|
160
|
+
</div>
|
|
161
|
+
</aside>
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<dl v-if="meta.length" class="ff-hero-meta">
|
|
165
|
+
<div v-for="item in meta" :key="item.label" class="ff-hero-meta-item">
|
|
166
|
+
<dt class="ff-label">{{ item.label }}</dt>
|
|
167
|
+
<dd>{{ item.value }}</dd>
|
|
168
|
+
</div>
|
|
169
|
+
</dl>
|
|
170
|
+
</div>
|
|
171
|
+
</template>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { computed } from 'vue'
|
|
2
|
+
import { useData } from 'vitepress'
|
|
3
|
+
import type { ThemeConfig, ThemeLabels, ThemeOptions } from '../types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Theme options declared under `themeConfig.ff`, with an empty object as a fallback so callers
|
|
7
|
+
* never have to guard.
|
|
8
|
+
*/
|
|
9
|
+
export function useThemeOptions() {
|
|
10
|
+
const { theme } = useData()
|
|
11
|
+
|
|
12
|
+
return computed<ThemeOptions>(() => (theme.value as ThemeConfig).ff ?? {})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** English fallbacks for every string this theme adds. */
|
|
16
|
+
export const defaultLabels: Required<ThemeLabels> = {
|
|
17
|
+
bannerDismiss: 'Dismiss announcement',
|
|
18
|
+
readingTime: '{0} min read',
|
|
19
|
+
lastUpdated: 'Updated {0}',
|
|
20
|
+
heroInstall: 'Install',
|
|
21
|
+
heroCopy: 'Copy',
|
|
22
|
+
heroCopied: 'Copied',
|
|
23
|
+
heroCopyLabel: 'Copy {0}',
|
|
24
|
+
backToTop: 'Top'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Labels for the current locale. VitePress merges `themeConfig` per locale before it reaches the
|
|
29
|
+
* client, so a site translates the theme by declaring `ff.labels` under each locale.
|
|
30
|
+
*/
|
|
31
|
+
export function useLabels() {
|
|
32
|
+
const options = useThemeOptions()
|
|
33
|
+
|
|
34
|
+
return computed<Required<ThemeLabels>>(() => {
|
|
35
|
+
const labels = { ...defaultLabels }
|
|
36
|
+
|
|
37
|
+
for (const [key, value] of Object.entries(options.value.labels ?? {})) {
|
|
38
|
+
if (value) labels[key as keyof ThemeLabels] = value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return labels
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Fills the `{0}` placeholder of a label. */
|
|
46
|
+
export function format(label: string, value: string | number) {
|
|
47
|
+
return label.replace('{0}', String(value))
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
/** Symbol being documented, e.g. `refs()`. */
|
|
4
|
+
name: string
|
|
5
|
+
/** Free-form kind label, e.g. `function`, `mixin`, `option`. */
|
|
6
|
+
kind?: string
|
|
7
|
+
/** One-line signature shown under the heading. */
|
|
8
|
+
signature?: string
|
|
9
|
+
/** Version the symbol appeared in. */
|
|
10
|
+
since?: string
|
|
11
|
+
/** Marks the symbol as deprecated. */
|
|
12
|
+
deprecated?: boolean
|
|
13
|
+
}>()
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<section class="ff-api" :class="{ 'is-deprecated': deprecated }">
|
|
18
|
+
<header class="ff-api-head">
|
|
19
|
+
<code class="ff-api-name">{{ name }}</code>
|
|
20
|
+
|
|
21
|
+
<span v-if="kind" class="ff-api-kind ff-label">{{ kind }}</span>
|
|
22
|
+
<span v-if="since" class="ff-api-tag ff-label">since {{ since }}</span>
|
|
23
|
+
<span v-if="deprecated" class="ff-api-tag ff-api-deprecated ff-label">deprecated</span>
|
|
24
|
+
</header>
|
|
25
|
+
|
|
26
|
+
<p v-if="signature" class="ff-api-signature"><code>{{ signature }}</code></p>
|
|
27
|
+
|
|
28
|
+
<div class="ff-api-body">
|
|
29
|
+
<slot />
|
|
30
|
+
</div>
|
|
31
|
+
</section>
|
|
32
|
+
</template>
|