@frontfactory/vitepress-theme 1.7.0 → 1.8.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/CHANGELOG.md +55 -0
- package/README.md +148 -5
- package/config.d.ts +26 -1
- package/config.js +165 -21
- package/dist/style.css +1 -1
- package/node/llms.js +31 -0
- package/node/og.js +159 -0
- package/node/pages.js +154 -0
- package/node/rss.js +81 -0
- package/package.json +42 -28
- package/src/blog/posts.data.ts +46 -0
- package/src/components/FfBackToTop.vue +18 -9
- package/src/components/FfBanner.vue +24 -6
- package/src/components/FfCopyStatus.vue +64 -0
- package/src/components/FfDocMeta.vue +41 -2
- package/src/components/FfFeature.vue +18 -7
- package/src/components/FfFeedback.vue +96 -0
- package/src/components/FfHero.vue +16 -6
- package/src/components/FfHeroCommand.vue +20 -34
- package/src/components/FfHomeSponsors.vue +2 -2
- package/src/components/FfNavBarTitle.vue +63 -0
- package/src/components/FfPost.vue +49 -0
- package/src/components/FfProgress.vue +69 -0
- package/src/components/FfVersionSwitcher.vue +20 -0
- package/src/composables/blog.ts +38 -0
- package/src/composables/options.ts +12 -1
- package/src/composables/tabs.ts +155 -0
- package/src/content/Api.vue +6 -2
- package/src/content/Badge.vue +26 -0
- package/src/content/Callout.vue +27 -0
- package/src/content/FileTree.vue +118 -0
- package/src/content/Tab.vue +11 -0
- package/src/content/Tabs.vue +74 -0
- package/src/content/Timeline.vue +19 -0
- package/src/content/TimelineItem.vue +37 -0
- package/src/content/timeline.ts +4 -0
- package/src/index.ts +37 -1
- package/src/internal.ts +7 -2
- package/src/layout/FfBlog.vue +62 -0
- package/src/layout/FfLayout.vue +17 -1
- package/src/styles/_base.scss +1 -5
- package/src/styles/_blocks.scss +25 -1
- package/src/styles/_blog.scss +131 -0
- package/src/styles/_breakpoints.scss +26 -0
- package/src/styles/_code.scss +5 -5
- package/src/styles/_content.scss +276 -7
- package/src/styles/_doc.scss +18 -5
- package/src/styles/_home.scss +37 -17
- package/src/styles/_motion.scss +12 -3
- package/src/styles/_nav.scss +81 -8
- package/src/styles/_print.scss +77 -0
- package/src/styles/_sidebar.scss +2 -2
- package/src/styles/_tokens.scss +73 -7
- package/src/styles/index.scss +2 -0
- package/src/types.ts +122 -0
- package/types/blog/posts.data.d.ts +14 -0
- package/types/components/FfBackToTop.vue.d.ts +3 -0
- package/types/components/FfBanner.vue.d.ts +3 -0
- package/types/components/FfCopyStatus.vue.d.ts +3 -0
- package/types/components/FfDocMeta.vue.d.ts +3 -0
- package/types/components/FfFeature.vue.d.ts +13 -0
- package/types/components/FfFeedback.vue.d.ts +3 -0
- package/types/components/FfFooter.vue.d.ts +3 -0
- package/types/components/FfHero.vue.d.ts +42 -0
- package/types/components/FfHeroCommand.vue.d.ts +9 -0
- package/types/components/FfHomeSponsors.vue.d.ts +19 -0
- package/types/components/FfNavBarTitle.vue.d.ts +17 -0
- package/types/components/FfPost.vue.d.ts +3 -0
- package/types/components/FfProgress.vue.d.ts +3 -0
- package/types/components/FfVersionSwitcher.vue.d.ts +3 -0
- package/types/composables/blog.d.ts +10 -0
- package/types/composables/link.d.ts +12 -0
- package/types/composables/options.d.ts +15 -0
- package/types/composables/relativeTime.d.ts +2 -0
- package/types/composables/tabs.d.ts +15 -0
- package/types/content/Api.vue.d.ts +27 -0
- package/types/content/Badge.vue.d.ts +21 -0
- package/types/content/Callout.vue.d.ts +24 -0
- package/types/content/Card.vue.d.ts +23 -0
- package/types/content/CardGrid.vue.d.ts +20 -0
- package/types/content/FileTree.vue.d.ts +6 -0
- package/types/content/Kbd.vue.d.ts +15 -0
- package/types/content/Steps.vue.d.ts +15 -0
- package/types/content/Tab.vue.d.ts +19 -0
- package/types/content/Tabs.vue.d.ts +7 -0
- package/types/content/Timeline.vue.d.ts +21 -0
- package/types/content/TimelineItem.vue.d.ts +21 -0
- package/types/content/timeline.d.ts +3 -0
- package/types/index.d.ts +25 -0
- package/types/internal.d.ts +9 -0
- package/types/layout/FfBlog.vue.d.ts +3 -0
- package/types/layout/FfLayout.vue.d.ts +23 -0
- package/types/types.d.ts +256 -0
package/node/rss.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { hostnameOf, readPages } from './pages.js';
|
|
4
|
+
|
|
5
|
+
/** Blog directory, without a slash at either end. */
|
|
6
|
+
export function blogDir(ff) {
|
|
7
|
+
return (ff.blog?.dir ?? 'blog').replace(/^\/+|\/+$/g, '');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Writes `feed.xml`, an RSS 2.0 feed of the blog posts (dated pages under the blog directory,
|
|
12
|
+
* newest first). `feed` is an optional peer dependency, so it is only loaded here, when the feed is
|
|
13
|
+
* actually requested.
|
|
14
|
+
*
|
|
15
|
+
* @param {import('vitepress').SiteConfig} siteConfig
|
|
16
|
+
*/
|
|
17
|
+
export async function generateRss(siteConfig) {
|
|
18
|
+
const ff = siteConfig.site.themeConfig.ff;
|
|
19
|
+
const rss = typeof ff.blog.rss === 'object' ? ff.blog.rss : {};
|
|
20
|
+
const hostname = hostnameOf(siteConfig, rss.hostname);
|
|
21
|
+
|
|
22
|
+
if (!hostname) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'[vitepress-theme] `ff.blog.rss` needs an absolute address: set `ff.blog.rss.hostname` or `sitemap.hostname`.'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let Feed;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
({ Feed } = await import('feed'));
|
|
32
|
+
} catch {
|
|
33
|
+
throw new Error('[vitepress-theme] `ff.blog.rss` needs the `feed` package: run `npm install feed`.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { title, description, lang, base } = siteConfig.site;
|
|
37
|
+
const authors = ff.blog.authors ?? {};
|
|
38
|
+
const dir = blogDir(ff);
|
|
39
|
+
const site = `${hostname}${base}`;
|
|
40
|
+
const feed = new Feed({
|
|
41
|
+
title,
|
|
42
|
+
description,
|
|
43
|
+
id: site,
|
|
44
|
+
link: site,
|
|
45
|
+
language: lang,
|
|
46
|
+
copyright: rss.copyright ?? '',
|
|
47
|
+
feedLinks: {
|
|
48
|
+
rss: `${site}feed.xml`
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const posts = (await readPages(siteConfig))
|
|
53
|
+
.filter(({ page, data }) => page.startsWith(`${dir}/`) && page !== `${dir}/index.md` && data.date)
|
|
54
|
+
.sort((a, b) => new Date(b.data.date) - new Date(a.data.date));
|
|
55
|
+
|
|
56
|
+
for (const { url, title: name, data } of posts) {
|
|
57
|
+
const author = authors[data.author] ?? (data.author ? {
|
|
58
|
+
name: data.author
|
|
59
|
+
} : null);
|
|
60
|
+
|
|
61
|
+
feed.addItem({
|
|
62
|
+
title: name,
|
|
63
|
+
id: `${hostname}${url}`,
|
|
64
|
+
link: `${hostname}${url}`,
|
|
65
|
+
description: data.excerpt,
|
|
66
|
+
date: new Date(data.date),
|
|
67
|
+
author: author ? [
|
|
68
|
+
author
|
|
69
|
+
] : undefined,
|
|
70
|
+
category: (Array.isArray(data.tags) ? data.tags : []).map((tag) => ({
|
|
71
|
+
name: tag
|
|
72
|
+
}))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await mkdir(siteConfig.outDir, {
|
|
77
|
+
recursive: true
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await writeFile(join(siteConfig.outDir, 'feed.xml'), feed.rss2());
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontfactory/vitepress-theme",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Editorial VitePress theme — hairline rules, numbered sections and monospaced metadata.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"
|
|
9
|
-
"dev
|
|
10
|
-
"
|
|
7
|
+
"build": "npm run build:css && npm run build:types",
|
|
8
|
+
"build:css": "sass --style=compressed --no-source-map --pkg-importer=node --load-path=node_modules src/styles/index.scss dist/style.css",
|
|
9
|
+
"dev": "npm run build:css -- --watch",
|
|
10
|
+
"dev:playground": "npm run build:css && vitepress dev playground",
|
|
11
|
+
"build:playground": "npm run build:css && vitepress build playground",
|
|
12
|
+
"build:types": "vue-tsc -p tsconfig.build.json",
|
|
11
13
|
"typecheck": "vue-tsc --noEmit",
|
|
14
|
+
"test:e2e": "playwright test tests/a11y.spec.ts",
|
|
12
15
|
"lint:js": "eslint .",
|
|
13
16
|
"lint:css": "stylelint \"src/**/*.scss\"",
|
|
14
17
|
"lint": "npm run lint:js && npm run lint:css",
|
|
@@ -19,12 +22,10 @@
|
|
|
19
22
|
"engines": {
|
|
20
23
|
"node": ">=24"
|
|
21
24
|
},
|
|
22
|
-
"
|
|
23
|
-
"module": "./src/index.ts",
|
|
24
|
-
"types": "./src/index.ts",
|
|
25
|
+
"types": "./types/index.d.ts",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
|
-
"types": "./
|
|
28
|
+
"types": "./types/index.d.ts",
|
|
28
29
|
"default": "./src/index.ts"
|
|
29
30
|
},
|
|
30
31
|
"./config": {
|
|
@@ -35,36 +36,47 @@
|
|
|
35
36
|
"./package.json": "./package.json"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@commitlint/
|
|
40
|
-
"@
|
|
41
|
-
"@front-factory/eslint-config": "^
|
|
42
|
-
"@front-factory/stylelint-config": "^
|
|
39
|
+
"@axe-core/playwright": "^4.14.0",
|
|
40
|
+
"@commitlint/cli": "^21.2.4",
|
|
41
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
42
|
+
"@front-factory/eslint-config": "^3.0.0",
|
|
43
|
+
"@front-factory/stylelint-config": "^2.0.0",
|
|
43
44
|
"@magnesium/theme": "^5.3.0",
|
|
45
|
+
"@playwright/test": "^1.64.1",
|
|
46
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
44
47
|
"@semantic-release/changelog": "^7.0.0",
|
|
45
48
|
"@semantic-release/git": "^11.0.1",
|
|
46
|
-
"@semantic-release/github": "^12.0.10",
|
|
47
49
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
48
|
-
"eslint": "^10.
|
|
49
|
-
"eslint-plugin-vue": "^10.
|
|
50
|
-
"
|
|
50
|
+
"eslint": "^10.14.0",
|
|
51
|
+
"eslint-plugin-vue": "^10.12.0",
|
|
52
|
+
"feed": "^6.0.0",
|
|
51
53
|
"husky": "^9.1.7",
|
|
52
|
-
"sass": "^1.
|
|
54
|
+
"sass": "^1.107.1",
|
|
55
|
+
"satori": "^0.63.2",
|
|
53
56
|
"semantic-release": "^25.0.9",
|
|
54
|
-
"stylelint": "^16.
|
|
55
|
-
"typescript": "^
|
|
56
|
-
"typescript-eslint": "^8.
|
|
57
|
-
"vitepress": "^2.0.0-alpha.
|
|
58
|
-
"vue": "^3.5.
|
|
59
|
-
"vue-tsc": "^3.3.
|
|
57
|
+
"stylelint": "^17.16.0",
|
|
58
|
+
"typescript": "^6.0.3",
|
|
59
|
+
"typescript-eslint": "^8.72.1",
|
|
60
|
+
"vitepress": "^2.0.0-alpha.21",
|
|
61
|
+
"vue": "^3.5.44",
|
|
62
|
+
"vue-tsc": "^3.3.14"
|
|
60
63
|
},
|
|
61
64
|
"peerDependencies": {
|
|
62
|
-
"
|
|
65
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
66
|
+
"feed": "^6.0.0",
|
|
67
|
+
"satori": "^0.63.2",
|
|
68
|
+
"vite": "^8.2.1",
|
|
63
69
|
"vitepress": "^2.0.0-alpha.20",
|
|
64
70
|
"vue": "^3.5.0"
|
|
65
71
|
},
|
|
66
72
|
"peerDependenciesMeta": {
|
|
67
|
-
"
|
|
73
|
+
"@resvg/resvg-js": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"feed": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"satori": {
|
|
68
80
|
"optional": true
|
|
69
81
|
}
|
|
70
82
|
},
|
|
@@ -91,9 +103,11 @@
|
|
|
91
103
|
"files": [
|
|
92
104
|
"src",
|
|
93
105
|
"dist/style.css",
|
|
106
|
+
"types",
|
|
94
107
|
"CHANGELOG.md",
|
|
95
108
|
"config.js",
|
|
96
|
-
"config.d.ts"
|
|
109
|
+
"config.d.ts",
|
|
110
|
+
"node"
|
|
97
111
|
],
|
|
98
112
|
"publishConfig": {
|
|
99
113
|
"access": "public",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createContentLoader, type LoaderModule } from 'vitepress';
|
|
2
|
+
import type { ThemeConfig } from '../types.ts';
|
|
3
|
+
|
|
4
|
+
export interface Post {
|
|
5
|
+
url: string
|
|
6
|
+
title: string
|
|
7
|
+
/** ISO date, as written in the frontmatter. */
|
|
8
|
+
date: string
|
|
9
|
+
author?: string
|
|
10
|
+
tags: string[]
|
|
11
|
+
excerpt?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare const data: Post[];
|
|
15
|
+
|
|
16
|
+
export { data };
|
|
17
|
+
|
|
18
|
+
// A data loader runs in Node, outside any component, so it cannot call `useData()`. VitePress puts
|
|
19
|
+
// the resolved config on `globalThis` before it evaluates a loader file (`createContentLoader`
|
|
20
|
+
// reads it the same way), which is where the blog directory is read from.
|
|
21
|
+
const { site } = (globalThis as unknown as { VITEPRESS_CONFIG: { site: { themeConfig?: ThemeConfig } } })
|
|
22
|
+
.VITEPRESS_CONFIG;
|
|
23
|
+
const dir = (site.themeConfig?.ff?.blog?.dir ?? 'blog').replace(/^\/+|\/+$/g, '');
|
|
24
|
+
|
|
25
|
+
// Annotated so the emitted declaration doesn't reference VitePress's private `GlobOptions` (TS4082).
|
|
26
|
+
const loader: LoaderModule<Post[]> = createContentLoader([
|
|
27
|
+
`${dir}/**/*.md`,
|
|
28
|
+
`!${dir}/index.md`
|
|
29
|
+
], {
|
|
30
|
+
includeSrc: true,
|
|
31
|
+
transform(raw) {
|
|
32
|
+
return raw
|
|
33
|
+
.filter(({ frontmatter }) => frontmatter.date)
|
|
34
|
+
.map(({ url, src, frontmatter }): Post => ({
|
|
35
|
+
url,
|
|
36
|
+
title: frontmatter.title || /^#\s+(.+)$/m.exec(src ?? '')?.[1].trim() || url,
|
|
37
|
+
date: new Date(frontmatter.date).toISOString(),
|
|
38
|
+
author: frontmatter.author,
|
|
39
|
+
tags: Array.isArray(frontmatter.tags) ? frontmatter.tags.map(String) : [],
|
|
40
|
+
excerpt: frontmatter.excerpt
|
|
41
|
+
}))
|
|
42
|
+
.sort((a, b) => b.date.localeCompare(a.date));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export default loader;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
computed, onMounted,
|
|
3
|
+
computed, onMounted, ref, watchEffect
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
@@ -40,16 +40,25 @@ function toTop() {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// Listens only while the control is enabled, and follows the option if it changes (locale switch).
|
|
44
|
+
// The effect is stopped with the component, which runs its cleanup.
|
|
43
45
|
onMounted(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
watchEffect((onCleanup) => {
|
|
47
|
+
if (!enabled.value) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
update();
|
|
52
|
+
window.addEventListener('scroll', onScroll, {
|
|
53
|
+
passive: true
|
|
54
|
+
});
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
onCleanup(() => {
|
|
57
|
+
cancelAnimationFrame(frame);
|
|
58
|
+
frame = 0;
|
|
59
|
+
window.removeEventListener('scroll', onScroll);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
53
62
|
});
|
|
54
63
|
</script>
|
|
55
64
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
computed, onMounted, onUnmounted, ref
|
|
3
|
+
computed, onMounted, onUnmounted, ref, watch
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
6
|
+
import { normalizeLink } from '../internal';
|
|
6
7
|
|
|
7
8
|
const options = useThemeOptions();
|
|
8
9
|
const labels = useLabels();
|
|
@@ -38,19 +39,36 @@ function dismiss() {
|
|
|
38
39
|
// Private mode or full quota: the banner is dismissed for this page view only.
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
// Read before hiding: a mouse click leaves no visible focus, so only a keyboard user is moved.
|
|
43
|
+
const keyboard = document.activeElement?.matches(':focus-visible') ?? false;
|
|
44
|
+
|
|
41
45
|
document.documentElement.classList.add(DISMISSED);
|
|
42
46
|
height();
|
|
47
|
+
|
|
48
|
+
// The banner goes `display: none` under the focused close button. Hand focus to the next stop,
|
|
49
|
+
// VitePress' skip link, instead of letting it drop to <body>.
|
|
50
|
+
if (keyboard) {
|
|
51
|
+
document.querySelector<HTMLElement>('.VPSkipLink')?.focus();
|
|
52
|
+
}
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
// The banner can appear or go away after mount (locale switch, `v-if`), so the observer follows the
|
|
56
|
+
// element rather than being wired once.
|
|
57
|
+
watch(el, (node) => {
|
|
58
|
+
observer?.disconnect();
|
|
59
|
+
observer = undefined;
|
|
46
60
|
height();
|
|
47
61
|
|
|
48
|
-
if (
|
|
62
|
+
if (node) {
|
|
49
63
|
observer = new ResizeObserver(height);
|
|
50
|
-
observer.observe(
|
|
64
|
+
observer.observe(node);
|
|
51
65
|
}
|
|
66
|
+
}, {
|
|
67
|
+
flush: 'post'
|
|
52
68
|
});
|
|
53
69
|
|
|
70
|
+
onMounted(height);
|
|
71
|
+
|
|
54
72
|
onUnmounted(() => {
|
|
55
73
|
observer?.disconnect();
|
|
56
74
|
document.documentElement.style.removeProperty('--vp-layout-top-height');
|
|
@@ -68,7 +86,7 @@ onUnmounted(() => {
|
|
|
68
86
|
<component
|
|
69
87
|
:is="banner.link ? 'a' : 'div'"
|
|
70
88
|
class="ff-banner-body"
|
|
71
|
-
:href="banner.link"
|
|
89
|
+
:href="banner.link ? normalizeLink(banner.link) : undefined"
|
|
72
90
|
>
|
|
73
91
|
<span
|
|
74
92
|
v-if="banner.icon"
|
|
@@ -83,7 +101,7 @@ onUnmounted(() => {
|
|
|
83
101
|
v-if="banner.link"
|
|
84
102
|
class="ff-banner-cta"
|
|
85
103
|
>
|
|
86
|
-
{{ banner.linkText ??
|
|
104
|
+
{{ banner.linkText ?? labels.bannerCta }}
|
|
87
105
|
<span aria-hidden="true">→</span>
|
|
88
106
|
</span>
|
|
89
107
|
</component>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
onMounted, onUnmounted, ref
|
|
4
|
+
} from 'vue';
|
|
5
|
+
import { useLabels } from '../composables/options';
|
|
6
|
+
|
|
7
|
+
const labels = useLabels();
|
|
8
|
+
const message = ref('');
|
|
9
|
+
|
|
10
|
+
// VitePress confirms a code block copy with a CSS `::before` only, which screen readers never
|
|
11
|
+
// hear. Its click handler adds `.copied` once the clipboard write succeeds, so the class is what
|
|
12
|
+
// gets watched rather than the click itself.
|
|
13
|
+
const BUTTON = 'div[class*="language-"] > button.copy';
|
|
14
|
+
|
|
15
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
16
|
+
|
|
17
|
+
function announce() {
|
|
18
|
+
message.value = labels.value.heroCopied;
|
|
19
|
+
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
timer = setTimeout(() => (message.value = ''), 2000);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onClick(event: MouseEvent) {
|
|
25
|
+
const button = (event.target as Element | null)?.closest?.(BUTTON);
|
|
26
|
+
|
|
27
|
+
if (!button) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Cleared first, so a second copy within two seconds is announced again.
|
|
32
|
+
message.value = '';
|
|
33
|
+
|
|
34
|
+
const observer = new MutationObserver(() => {
|
|
35
|
+
if (button.classList.contains('copied')) {
|
|
36
|
+
observer.disconnect();
|
|
37
|
+
announce();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
observer.observe(button, {
|
|
42
|
+
attributeFilter: [
|
|
43
|
+
'class'
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// A failed write never adds the class: stop watching once the confirmation window is over.
|
|
48
|
+
setTimeout(() => observer.disconnect(), 2000);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onMounted(() => window.addEventListener('click', onClick));
|
|
52
|
+
|
|
53
|
+
onUnmounted(() => {
|
|
54
|
+
window.removeEventListener('click', onClick);
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<span
|
|
61
|
+
class="visually-hidden"
|
|
62
|
+
aria-live="polite"
|
|
63
|
+
>{{ message }}</span>
|
|
64
|
+
</template>
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLayout } from '../internal';
|
|
7
|
+
import { useCopy } from '../composables/tabs';
|
|
7
8
|
import { formatRelative } from '../composables/relativeTime';
|
|
8
9
|
import {
|
|
9
10
|
format, useLabels, useThemeOptions
|
|
@@ -64,14 +65,26 @@ const section = computed(() => {
|
|
|
64
65
|
|
|
65
66
|
const words = ref(0);
|
|
66
67
|
|
|
68
|
+
// Splitting the whole page is only worth it when the estimate can be shown.
|
|
69
|
+
const measured = computed(() => !!meta.value && meta.value.readingTime !== false);
|
|
70
|
+
|
|
67
71
|
function measure() {
|
|
72
|
+
if (!measured.value) {
|
|
73
|
+
words.value = 0;
|
|
74
|
+
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
words.value =
|
|
69
79
|
document.querySelector('.vp-doc')?.textContent?.trim().split(/\s+/).filter(Boolean)
|
|
70
80
|
.length ?? 0;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
onMounted(() => nextTick(measure));
|
|
74
|
-
watch(
|
|
84
|
+
watch([
|
|
85
|
+
() => page.value.relativePath,
|
|
86
|
+
measured
|
|
87
|
+
], () => nextTick(measure));
|
|
75
88
|
|
|
76
89
|
const minutes = computed(() => {
|
|
77
90
|
if (!meta.value || meta.value.readingTime === false || !words.value) {
|
|
@@ -97,7 +110,23 @@ const updatedAt = computed(() =>
|
|
|
97
110
|
page.value.lastUpdated ? new Date(page.value.lastUpdated).toISOString() : undefined
|
|
98
111
|
);
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
// --------------------------------------------------------------------------------------------- //
|
|
114
|
+
// Copy as Markdown
|
|
115
|
+
//
|
|
116
|
+
// The source is put on the page data at build time by `ffTransformPageData`; without it the
|
|
117
|
+
// button has nothing to copy and stays out.
|
|
118
|
+
// --------------------------------------------------------------------------------------------- //
|
|
119
|
+
|
|
120
|
+
const markdown = computed(() => (page.value as { ffMarkdown?: string }).ffMarkdown ?? '');
|
|
121
|
+
|
|
122
|
+
const copyable = computed(() => options.value.copyMarkdown === true && !!markdown.value);
|
|
123
|
+
|
|
124
|
+
const { copied, copy } = useCopy(markdown);
|
|
125
|
+
|
|
126
|
+
// The block stays for the button even when the kicker itself is switched off.
|
|
127
|
+
const hidden = computed(
|
|
128
|
+
() => (!meta.value && !copyable.value) || frontmatter.value.layout === 'home'
|
|
129
|
+
);
|
|
101
130
|
</script>
|
|
102
131
|
|
|
103
132
|
<template>
|
|
@@ -125,5 +154,15 @@ const hidden = computed(() => !meta.value || frontmatter.value.layout === 'home'
|
|
|
125
154
|
{{ format(labels.lastUpdated, updated) }}
|
|
126
155
|
</time>
|
|
127
156
|
</ClientOnly>
|
|
157
|
+
|
|
158
|
+
<button
|
|
159
|
+
v-if="copyable"
|
|
160
|
+
type="button"
|
|
161
|
+
class="ff-doc-meta-copy"
|
|
162
|
+
:class="{ copied }"
|
|
163
|
+
@click="copy"
|
|
164
|
+
>
|
|
165
|
+
<span aria-live="polite">{{ copied ? labels.heroCopied : labels.copyMarkdown }}</span>
|
|
166
|
+
</button>
|
|
128
167
|
</div>
|
|
129
168
|
</template>
|
|
@@ -15,9 +15,11 @@ const props = defineProps<{
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<template>
|
|
18
|
-
|
|
18
|
+
<!-- Only the title is the link, stretched over the card in CSS: wrapping the whole card made the
|
|
19
|
+
heading, details and call to action all part of the link's accessible name. -->
|
|
20
|
+
<article
|
|
19
21
|
class="VPFeature ff-feature"
|
|
20
|
-
|
|
22
|
+
:class="{ 'ff-feature-linked': link }"
|
|
21
23
|
>
|
|
22
24
|
<span
|
|
23
25
|
class="ff-feature-index"
|
|
@@ -42,10 +44,19 @@ const props = defineProps<{
|
|
|
42
44
|
v-html="icon"
|
|
43
45
|
/>
|
|
44
46
|
|
|
45
|
-
<h2
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
<h2 class="ff-feature-title">
|
|
48
|
+
<VPLink
|
|
49
|
+
v-if="link"
|
|
50
|
+
class="ff-feature-anchor"
|
|
51
|
+
v-bind="cardLinkProps(props.link, props.rel, props.target)"
|
|
52
|
+
>
|
|
53
|
+
<span v-html="title" />
|
|
54
|
+
</VPLink>
|
|
55
|
+
<span
|
|
56
|
+
v-else
|
|
57
|
+
v-html="title"
|
|
58
|
+
/>
|
|
59
|
+
</h2>
|
|
49
60
|
|
|
50
61
|
<ul
|
|
51
62
|
v-if="Array.isArray(details)"
|
|
@@ -70,5 +81,5 @@ const props = defineProps<{
|
|
|
70
81
|
{{ linkText }}
|
|
71
82
|
<span aria-hidden="true">→</span>
|
|
72
83
|
</span>
|
|
73
|
-
</
|
|
84
|
+
</article>
|
|
74
85
|
</template>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
computed, nextTick, ref, watch
|
|
4
|
+
} from 'vue';
|
|
5
|
+
import { useData } from 'vitepress';
|
|
6
|
+
import { useLabels, useThemeOptions } from '../composables/options';
|
|
7
|
+
|
|
8
|
+
const { page, frontmatter, lang } = useData();
|
|
9
|
+
const options = useThemeOptions();
|
|
10
|
+
const labels = useLabels();
|
|
11
|
+
|
|
12
|
+
const config = computed(() => {
|
|
13
|
+
const { feedback } = options.value;
|
|
14
|
+
|
|
15
|
+
if (!feedback || frontmatter.value.feedback === false) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return feedback === true ? {} : feedback;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const question = computed(() => config.value?.question || labels.value.feedbackQuestion);
|
|
23
|
+
|
|
24
|
+
const voted = ref(false);
|
|
25
|
+
const thanks = ref<HTMLElement | null>(null);
|
|
26
|
+
|
|
27
|
+
// The widget is reused across client-side navigation, so each page starts unanswered.
|
|
28
|
+
watch(() => page.value.relativePath, () => (voted.value = false));
|
|
29
|
+
|
|
30
|
+
function vote(value: 'yes' | 'no') {
|
|
31
|
+
const payload = {
|
|
32
|
+
page: page.value.relativePath,
|
|
33
|
+
value,
|
|
34
|
+
lang: lang.value
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
voted.value = true;
|
|
38
|
+
|
|
39
|
+
// The buttons leave the DOM with the vote: hand focus to the thank-you line instead of <body>.
|
|
40
|
+
nextTick(() => thanks.value?.focus());
|
|
41
|
+
|
|
42
|
+
// A string keeps the request CORS-safelisted (text/plain); a JSON Blob would trigger a
|
|
43
|
+
// preflight that cross-origin endpoints rarely answer.
|
|
44
|
+
if (config.value?.url) {
|
|
45
|
+
navigator.sendBeacon(config.value.url, JSON.stringify(payload));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Always emitted, so a site can forward the vote itself (a function cannot live in `themeConfig`).
|
|
49
|
+
window.dispatchEvent(new CustomEvent('ff:feedback', {
|
|
50
|
+
detail: payload
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div
|
|
57
|
+
v-if="config"
|
|
58
|
+
class="ff-feedback"
|
|
59
|
+
>
|
|
60
|
+
<p
|
|
61
|
+
v-if="!voted"
|
|
62
|
+
class="ff-feedback-question ff-label"
|
|
63
|
+
>
|
|
64
|
+
{{ question }}
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<div
|
|
68
|
+
v-if="!voted"
|
|
69
|
+
class="ff-feedback-actions"
|
|
70
|
+
>
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
class="ff-feedback-button ff-label"
|
|
74
|
+
@click="vote('yes')"
|
|
75
|
+
>
|
|
76
|
+
{{ labels.feedbackYes }}
|
|
77
|
+
</button>
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
class="ff-feedback-button ff-label"
|
|
81
|
+
@click="vote('no')"
|
|
82
|
+
>
|
|
83
|
+
{{ labels.feedbackNo }}
|
|
84
|
+
</button>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<p
|
|
88
|
+
ref="thanks"
|
|
89
|
+
class="ff-feedback-thanks ff-label"
|
|
90
|
+
tabindex="-1"
|
|
91
|
+
aria-live="polite"
|
|
92
|
+
>
|
|
93
|
+
{{ voted ? labels.feedbackThanks : '' }}
|
|
94
|
+
</p>
|
|
95
|
+
</div>
|
|
96
|
+
</template>
|