@frontfactory/vitepress-theme 1.8.0 → 1.10.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 +39 -0
- package/README.md +11 -391
- package/config.d.ts +4 -3
- package/config.js +58 -40
- package/dist/style.css +1 -1
- package/node/banner.d.ts +3 -0
- package/node/banner.js +14 -0
- package/node/blog.d.ts +11 -0
- package/node/blog.js +63 -0
- package/node/llms.js +4 -3
- package/node/og.js +5 -6
- package/node/options.d.ts +1 -0
- package/node/options.js +17 -0
- package/node/page-actions.d.ts +12 -0
- package/node/page-actions.js +34 -0
- package/node/pages.js +34 -14
- package/node/rss.js +13 -21
- package/package.json +1 -1
- package/src/blog/posts.data.ts +7 -4
- package/src/components/FfBackToTop.vue +6 -36
- package/src/components/FfBanner.vue +3 -2
- package/src/components/FfCopyStatus.vue +6 -14
- package/src/components/FfDocMeta.vue +299 -24
- package/src/components/FfFeedback.vue +4 -9
- package/src/components/FfHero.vue +14 -33
- package/src/components/FfHeroActions.vue +44 -0
- package/src/components/FfHeroCommand.vue +3 -2
- package/src/components/FfPost.vue +6 -4
- package/src/components/FfProgress.vue +6 -40
- package/src/composables/blog.ts +8 -11
- package/src/composables/copy.ts +29 -0
- package/src/composables/frame.ts +50 -0
- package/src/composables/options.ts +9 -1
- package/src/composables/tabs.ts +2 -35
- package/src/composables/transient.ts +27 -0
- package/src/content/Tabs.vue +27 -6
- package/src/internal.ts +1 -0
- package/src/layout/FfLayout.vue +3 -3
- package/src/styles/_base.scss +5 -9
- package/src/styles/_blocks.scss +4 -7
- package/src/styles/_blog.scss +4 -5
- package/src/styles/_code.scss +12 -20
- package/src/styles/_content.scss +153 -63
- package/src/styles/_doc.scss +26 -25
- package/src/styles/_home.scss +31 -61
- package/src/styles/_mixins.scss +87 -0
- package/src/styles/_motion.scss +12 -10
- package/src/styles/_nav.scss +12 -19
- package/src/styles/_sidebar.scss +5 -8
- package/src/styles/_tokens.scss +19 -4
- package/src/types.ts +31 -4
- package/types/components/FfHeroActions.vue.d.ts +19 -0
- package/types/composables/blog.d.ts +3 -4
- package/types/composables/copy.d.ts +6 -0
- package/types/composables/frame.d.ts +6 -0
- package/types/composables/tabs.d.ts +0 -5
- package/types/composables/transient.d.ts +6 -0
- package/types/internal.d.ts +1 -0
- package/types/types.d.ts +29 -4
package/node/rss.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
import {
|
|
4
|
+
blogDir, isPostPath, resolveAuthor, toTags
|
|
5
|
+
} from './blog.js';
|
|
6
|
+
import { resolveOption } from './options.js';
|
|
7
|
+
import { requireHostname } from './pages.js';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Writes `feed.xml`, an RSS 2.0 feed of the blog posts (dated pages under the blog directory,
|
|
@@ -13,17 +12,12 @@ export function blogDir(ff) {
|
|
|
13
12
|
* actually requested.
|
|
14
13
|
*
|
|
15
14
|
* @param {import('vitepress').SiteConfig} siteConfig
|
|
15
|
+
* @param {Awaited<ReturnType<typeof import('./pages.js').readPages>>} allPages Pages read once by the caller.
|
|
16
16
|
*/
|
|
17
|
-
export async function generateRss(siteConfig) {
|
|
17
|
+
export async function generateRss(siteConfig, allPages) {
|
|
18
18
|
const ff = siteConfig.site.themeConfig.ff;
|
|
19
|
-
const rss =
|
|
20
|
-
const 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
|
-
}
|
|
19
|
+
const rss = resolveOption(ff.blog.rss) ?? {};
|
|
20
|
+
const hostname = requireHostname(siteConfig, rss.hostname, 'ff.blog.rss');
|
|
27
21
|
|
|
28
22
|
let Feed;
|
|
29
23
|
|
|
@@ -49,14 +43,12 @@ export async function generateRss(siteConfig) {
|
|
|
49
43
|
}
|
|
50
44
|
});
|
|
51
45
|
|
|
52
|
-
const posts =
|
|
53
|
-
.filter(({ page, data }) =>
|
|
46
|
+
const posts = allPages
|
|
47
|
+
.filter(({ page, data }) => isPostPath(dir, page, data.date))
|
|
54
48
|
.sort((a, b) => new Date(b.data.date) - new Date(a.data.date));
|
|
55
49
|
|
|
56
50
|
for (const { url, title: name, data } of posts) {
|
|
57
|
-
const author = authors
|
|
58
|
-
name: data.author
|
|
59
|
-
} : null);
|
|
51
|
+
const author = resolveAuthor(authors, data.author);
|
|
60
52
|
|
|
61
53
|
feed.addItem({
|
|
62
54
|
title: name,
|
|
@@ -67,7 +59,7 @@ export async function generateRss(siteConfig) {
|
|
|
67
59
|
author: author ? [
|
|
68
60
|
author
|
|
69
61
|
] : undefined,
|
|
70
|
-
category: (
|
|
62
|
+
category: toTags(data.tags).map((tag) => ({
|
|
71
63
|
name: tag
|
|
72
64
|
}))
|
|
73
65
|
});
|
package/package.json
CHANGED
package/src/blog/posts.data.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createContentLoader, type LoaderModule } from 'vitepress';
|
|
2
2
|
import type { ThemeConfig } from '../types.ts';
|
|
3
|
+
import {
|
|
4
|
+
blogDir, firstHeading, hasValidDate, toTags
|
|
5
|
+
} from '../../node/blog.js';
|
|
3
6
|
|
|
4
7
|
export interface Post {
|
|
5
8
|
url: string
|
|
@@ -20,7 +23,7 @@ export { data };
|
|
|
20
23
|
// reads it the same way), which is where the blog directory is read from.
|
|
21
24
|
const { site } = (globalThis as unknown as { VITEPRESS_CONFIG: { site: { themeConfig?: ThemeConfig } } })
|
|
22
25
|
.VITEPRESS_CONFIG;
|
|
23
|
-
const dir = (site.themeConfig?.ff
|
|
26
|
+
const dir = blogDir(site.themeConfig?.ff);
|
|
24
27
|
|
|
25
28
|
// Annotated so the emitted declaration doesn't reference VitePress's private `GlobOptions` (TS4082).
|
|
26
29
|
const loader: LoaderModule<Post[]> = createContentLoader([
|
|
@@ -30,13 +33,13 @@ const loader: LoaderModule<Post[]> = createContentLoader([
|
|
|
30
33
|
includeSrc: true,
|
|
31
34
|
transform(raw) {
|
|
32
35
|
return raw
|
|
33
|
-
.filter(({ frontmatter }) => frontmatter.date)
|
|
36
|
+
.filter(({ frontmatter }) => hasValidDate(frontmatter.date))
|
|
34
37
|
.map(({ url, src, frontmatter }): Post => ({
|
|
35
38
|
url,
|
|
36
|
-
title: frontmatter.title ||
|
|
39
|
+
title: frontmatter.title || firstHeading(src ?? '') || url,
|
|
37
40
|
date: new Date(frontmatter.date).toISOString(),
|
|
38
41
|
author: frontmatter.author,
|
|
39
|
-
tags:
|
|
42
|
+
tags: toTags(frontmatter.tags).map(String),
|
|
40
43
|
excerpt: frontmatter.excerpt
|
|
41
44
|
}))
|
|
42
45
|
.sort((a, b) => b.date.localeCompare(a.date));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
computed, onMounted, ref, watchEffect
|
|
4
|
-
} from 'vue';
|
|
2
|
+
import { computed, ref } from 'vue';
|
|
5
3
|
import { useData } from 'vitepress';
|
|
6
4
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
5
|
+
import { useFrameListener } from '../composables/frame';
|
|
7
6
|
|
|
8
7
|
const { theme } = useData();
|
|
9
8
|
const options = useThemeOptions();
|
|
@@ -11,7 +10,7 @@ const labels = useLabels();
|
|
|
11
10
|
|
|
12
11
|
// The visible text is the accessible name; the tooltip reuses the default theme's own option,
|
|
13
12
|
// so a site that already localised its mobile return-to-top link gets this one for free.
|
|
14
|
-
const title = computed(() => theme.value.returnToTopLabel ??
|
|
13
|
+
const title = computed(() => theme.value.returnToTopLabel ?? labels.value.returnToTop);
|
|
15
14
|
|
|
16
15
|
const enabled = computed(() => options.value.backToTop !== false);
|
|
17
16
|
|
|
@@ -21,18 +20,6 @@ function update() {
|
|
|
21
20
|
visible.value = window.scrollY > window.innerHeight;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
// At most one state update per frame, however many scroll events fire.
|
|
25
|
-
let frame = 0;
|
|
26
|
-
|
|
27
|
-
function onScroll() {
|
|
28
|
-
if (!frame) {
|
|
29
|
-
frame = requestAnimationFrame(() => {
|
|
30
|
-
frame = 0;
|
|
31
|
-
update();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
23
|
function toTop() {
|
|
37
24
|
window.scrollTo({
|
|
38
25
|
top: 0,
|
|
@@ -40,26 +27,9 @@ function toTop() {
|
|
|
40
27
|
});
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
watchEffect((onCleanup) => {
|
|
47
|
-
if (!enabled.value) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
update();
|
|
52
|
-
window.addEventListener('scroll', onScroll, {
|
|
53
|
-
passive: true
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
onCleanup(() => {
|
|
57
|
-
cancelAnimationFrame(frame);
|
|
58
|
-
frame = 0;
|
|
59
|
-
window.removeEventListener('scroll', onScroll);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
30
|
+
useFrameListener(enabled, update, [
|
|
31
|
+
'scroll'
|
|
32
|
+
]);
|
|
63
33
|
</script>
|
|
64
34
|
|
|
65
35
|
<template>
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
6
6
|
import { normalizeLink } from '../internal';
|
|
7
|
+
import { BANNER_DISMISSED_CLASS, bannerKey } from '../../node/banner.js';
|
|
7
8
|
|
|
8
9
|
const options = useThemeOptions();
|
|
9
10
|
const labels = useLabels();
|
|
@@ -14,7 +15,7 @@ let observer: ResizeObserver | undefined;
|
|
|
14
15
|
|
|
15
16
|
// The class is set on <html> by an inline script injected in the head, so a dismissed banner never
|
|
16
17
|
// paints. See transformHead() in config.js.
|
|
17
|
-
const DISMISSED =
|
|
18
|
+
const DISMISSED = BANNER_DISMISSED_CLASS;
|
|
18
19
|
|
|
19
20
|
function height() {
|
|
20
21
|
const root = document.documentElement;
|
|
@@ -34,7 +35,7 @@ function dismiss() {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
try {
|
|
37
|
-
localStorage.setItem(
|
|
38
|
+
localStorage.setItem(bannerKey(banner.value.id), 'dismissed');
|
|
38
39
|
} catch {
|
|
39
40
|
// Private mode or full quota: the banner is dismissed for this page view only.
|
|
40
41
|
}
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
onMounted, onUnmounted
|
|
3
|
+
computed, onMounted, onUnmounted
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useLabels } from '../composables/options';
|
|
6
|
+
import { useTransientFlag } from '../composables/transient';
|
|
6
7
|
|
|
7
8
|
const labels = useLabels();
|
|
8
|
-
const
|
|
9
|
+
const { active, start, stop } = useTransientFlag();
|
|
10
|
+
const message = computed(() => (active.value ? labels.value.codeCopied : ''));
|
|
9
11
|
|
|
10
12
|
// VitePress confirms a code block copy with a CSS `::before` only, which screen readers never
|
|
11
13
|
// hear. Its click handler adds `.copied` once the clipboard write succeeds, so the class is what
|
|
12
14
|
// gets watched rather than the click itself.
|
|
13
15
|
const BUTTON = 'div[class*="language-"] > button.copy';
|
|
14
16
|
|
|
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
17
|
function onClick(event: MouseEvent) {
|
|
25
18
|
const button = (event.target as Element | null)?.closest?.(BUTTON);
|
|
26
19
|
|
|
@@ -29,12 +22,12 @@ function onClick(event: MouseEvent) {
|
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
// Cleared first, so a second copy within two seconds is announced again.
|
|
32
|
-
|
|
25
|
+
stop();
|
|
33
26
|
|
|
34
27
|
const observer = new MutationObserver(() => {
|
|
35
28
|
if (button.classList.contains('copied')) {
|
|
36
29
|
observer.disconnect();
|
|
37
|
-
|
|
30
|
+
start();
|
|
38
31
|
}
|
|
39
32
|
});
|
|
40
33
|
|
|
@@ -52,7 +45,6 @@ onMounted(() => window.addEventListener('click', onClick));
|
|
|
52
45
|
|
|
53
46
|
onUnmounted(() => {
|
|
54
47
|
window.removeEventListener('click', onClick);
|
|
55
|
-
clearTimeout(timer);
|
|
56
48
|
});
|
|
57
49
|
</script>
|
|
58
50
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
computed, nextTick, onMounted, ref, watch
|
|
3
|
+
computed, h, nextTick, onMounted, onUnmounted, ref, watch
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLayout } from '../internal';
|
|
7
|
-
import { useCopy } from '../composables/
|
|
7
|
+
import { useCopy } from '../composables/copy';
|
|
8
|
+
import { resolveOption } from '../../node/options.js';
|
|
9
|
+
import { resolvePageActions, type Network } from '../../node/page-actions.js';
|
|
8
10
|
import { formatRelative } from '../composables/relativeTime';
|
|
9
11
|
import {
|
|
10
12
|
format, useLabels, useThemeOptions
|
|
@@ -16,13 +18,9 @@ const { sidebarGroups } = useLayout();
|
|
|
16
18
|
const options = useThemeOptions();
|
|
17
19
|
const labels = useLabels();
|
|
18
20
|
|
|
19
|
-
const meta = computed(() =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return options.value.meta ?? {};
|
|
25
|
-
});
|
|
21
|
+
const meta = computed(() =>
|
|
22
|
+
resolveOption(options.value.meta ?? true, frontmatter.value.docMeta === false)
|
|
23
|
+
);
|
|
26
24
|
|
|
27
25
|
// --------------------------------------------------------------------------------------------- //
|
|
28
26
|
// Section, read from the sidebar the site already declares
|
|
@@ -111,21 +109,215 @@ const updatedAt = computed(() =>
|
|
|
111
109
|
);
|
|
112
110
|
|
|
113
111
|
// --------------------------------------------------------------------------------------------- //
|
|
114
|
-
//
|
|
112
|
+
// Page actions menu
|
|
115
113
|
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
114
|
+
// Copying the Markdown source needs `ffMarkdown`, put on the page data at build time by
|
|
115
|
+
// `ffTransformPageData`; without it that action stays out. `copyMarkdown` is the older spelling of
|
|
116
|
+
// `pageActions: { copyMarkdown: true }`.
|
|
118
117
|
// --------------------------------------------------------------------------------------------- //
|
|
119
118
|
|
|
119
|
+
// 24px viewBox paths: the interface icons are stroked, the brand ones (Simple Icons, CC0) filled.
|
|
120
|
+
const icons = {
|
|
121
|
+
copy: 'M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2zM4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2',
|
|
122
|
+
check: 'M20 6 9 17l-5-5',
|
|
123
|
+
link: 'M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71',
|
|
124
|
+
share: 'M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13',
|
|
125
|
+
chevron: 'm6 9 6 6 6-6',
|
|
126
|
+
external: 'M7 7h10v10M7 17 17 7'
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const brands: Record<Network, string> = {
|
|
130
|
+
x: 'M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z',
|
|
131
|
+
linkedin: 'M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z',
|
|
132
|
+
bluesky: 'M12 10.8c-1.087-2.114-4.046-6.053-6.798-7.995C2.566.944 1.561 1.266.902 1.565.139 1.908 0 3.08 0 3.768c0 .69.378 5.65.624 6.479.815 2.736 3.713 3.66 6.383 3.364.136-.02.275-.039.415-.056-.138.022-.276.04-.415.056-3.912.58-7.387 2.005-2.83 7.078 5.013 5.19 6.87-1.113 7.823-4.308.953 3.195 2.05 9.271 7.733 4.308 4.267-4.308 1.172-6.498-2.74-7.078a8.741 8.741 0 0 1-.415-.056c.14.017.279.036.415.056 2.67.297 5.568-.628 6.383-3.364.246-.828.624-5.79.624-6.478 0-.69-.139-1.861-.902-2.206-.659-.298-1.664-.62-4.3 1.24C16.046 4.748 13.087 8.687 12 10.8Z',
|
|
133
|
+
mastodon: 'M23.268 5.313c-.35-2.578-2.617-4.61-5.304-5.004C17.51.242 15.792 0 11.813 0h-.03c-3.98 0-4.835.242-5.288.309C3.882.692 1.496 2.518.917 5.127.64 6.412.61 7.837.661 9.143c.074 1.874.088 3.745.26 5.611.118 1.24.325 2.47.62 3.68.55 2.237 2.777 4.098 4.96 4.857 2.336.792 4.849.923 7.256.38.265-.061.527-.132.786-.213.585-.184 1.27-.39 1.774-.753a.057.057 0 0 0 .023-.043v-1.809a.052.052 0 0 0-.02-.041.053.053 0 0 0-.046-.01 20.282 20.282 0 0 1-4.709.545c-2.73 0-3.463-1.284-3.674-1.818a5.593 5.593 0 0 1-.319-1.433.053.053 0 0 1 .066-.054c1.517.363 3.072.546 4.632.546.376 0 .75 0 1.125-.01 1.57-.044 3.224-.124 4.768-.422.038-.008.077-.015.11-.024 2.435-.464 4.753-1.92 4.989-5.604.008-.145.03-1.52.03-1.67.002-.512.167-3.63-.024-5.545zm-3.748 9.195h-2.561V8.29c0-1.309-.55-1.976-1.67-1.976-1.23 0-1.846.79-1.846 2.35v3.403h-2.546V8.663c0-1.56-.617-2.35-1.848-2.35-1.112 0-1.668.668-1.67 1.977v6.218H4.822V8.102c0-1.31.337-2.35 1.011-3.12.696-.77 1.608-1.164 2.74-1.164 1.311 0 2.302.5 2.962 1.498l.638 1.06.638-1.06c.66-.999 1.65-1.498 2.96-1.498 1.13 0 2.043.395 2.74 1.164.675.77 1.012 1.81 1.012 3.12z'
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const networks: Record<
|
|
137
|
+
Network,
|
|
138
|
+
{
|
|
139
|
+
name: string
|
|
140
|
+
url: (url: string, text: string, instance: string) => string
|
|
141
|
+
}
|
|
142
|
+
> = {
|
|
143
|
+
x: {
|
|
144
|
+
name: 'X',
|
|
145
|
+
url: (url, text) =>
|
|
146
|
+
`https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`
|
|
147
|
+
},
|
|
148
|
+
linkedin: {
|
|
149
|
+
name: 'LinkedIn',
|
|
150
|
+
url: (url) =>
|
|
151
|
+
`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`
|
|
152
|
+
},
|
|
153
|
+
bluesky: {
|
|
154
|
+
name: 'Bluesky',
|
|
155
|
+
url: (url, text) =>
|
|
156
|
+
`https://bsky.app/intent/compose?text=${encodeURIComponent(`${text} ${url}`)}`
|
|
157
|
+
},
|
|
158
|
+
mastodon: {
|
|
159
|
+
name: 'Mastodon',
|
|
160
|
+
url: (url, text, instance) =>
|
|
161
|
+
`https://${instance}/share?text=${encodeURIComponent(`${text} ${url}`)}`
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Renders one of the paths above.
|
|
166
|
+
const MetaIcon = (props: { d: string;
|
|
167
|
+
brand?: boolean }) =>
|
|
168
|
+
h(
|
|
169
|
+
'svg',
|
|
170
|
+
{
|
|
171
|
+
class: [
|
|
172
|
+
'ff-doc-meta-icon',
|
|
173
|
+
{
|
|
174
|
+
brand: props.brand
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
viewBox: '0 0 24 24',
|
|
178
|
+
'aria-hidden': 'true'
|
|
179
|
+
},
|
|
180
|
+
h('path', {
|
|
181
|
+
d: props.d
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
MetaIcon.props = [
|
|
186
|
+
'd',
|
|
187
|
+
'brand'
|
|
188
|
+
];
|
|
189
|
+
|
|
120
190
|
const markdown = computed(() => (page.value as { ffMarkdown?: string }).ffMarkdown ?? '');
|
|
121
191
|
|
|
122
|
-
const
|
|
192
|
+
const actions = computed(() => {
|
|
193
|
+
const resolved = resolvePageActions(options.value);
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
...resolved,
|
|
197
|
+
markdown: resolved.markdown && !!markdown.value
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const available = computed(
|
|
202
|
+
() => actions.value.markdown || actions.value.link || actions.value.share.length > 0
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// The main part of the split button copies the link, else the Markdown; with neither, the single
|
|
206
|
+
// "Share" trigger takes its place. The menu never repeats the main action.
|
|
207
|
+
const main = computed(() =>
|
|
208
|
+
actions.value.link ? 'link' : actions.value.markdown ? 'markdown' : null
|
|
209
|
+
);
|
|
210
|
+
const menuMarkdown = computed(() => main.value === 'link' && actions.value.markdown);
|
|
211
|
+
const hasMenu = computed(() => menuMarkdown.value || actions.value.share.length > 0);
|
|
212
|
+
|
|
213
|
+
// The page address without its query or hash, read on the client only.
|
|
214
|
+
function pageAddress() {
|
|
215
|
+
return window.location.origin + window.location.pathname;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const { copied: markdownCopied, copy: copyMarkdown } = useCopy(markdown);
|
|
219
|
+
const { copied: linkCopied, copy: copyLink } = useCopy(pageAddress);
|
|
220
|
+
|
|
221
|
+
const copied = computed(() => markdownCopied.value || linkCopied.value);
|
|
222
|
+
const message = computed(() =>
|
|
223
|
+
linkCopied.value ? labels.value.linkCopied : markdownCopied.value ? labels.value.heroCopied : ''
|
|
224
|
+
);
|
|
225
|
+
const mainLabel = computed(
|
|
226
|
+
() =>
|
|
227
|
+
message.value ||
|
|
228
|
+
(main.value === 'link' ? labels.value.copyLink : labels.value.copyMarkdown)
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const root = ref<HTMLElement>();
|
|
232
|
+
const trigger = ref<HTMLButtonElement>();
|
|
233
|
+
const open = ref(false);
|
|
234
|
+
const pageUrl = ref('');
|
|
235
|
+
|
|
236
|
+
const shares = computed(() =>
|
|
237
|
+
actions.value.share
|
|
238
|
+
.filter((id) => networks[id])
|
|
239
|
+
.map((id) => ({
|
|
240
|
+
id,
|
|
241
|
+
name: networks[id].name,
|
|
242
|
+
href: networks[id].url(pageUrl.value, page.value.title, actions.value.instance)
|
|
243
|
+
}))
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
function toggle() {
|
|
247
|
+
open.value = !open.value;
|
|
248
|
+
|
|
249
|
+
if (open.value) {
|
|
250
|
+
// Read on the client only, so the page renders the same on the server.
|
|
251
|
+
pageUrl.value = pageAddress();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function close(refocus = false) {
|
|
256
|
+
open.value = false;
|
|
257
|
+
|
|
258
|
+
if (refocus) {
|
|
259
|
+
trigger.value?.focus();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A link is only followed once its handlers return, so the menu leaves after it.
|
|
264
|
+
function closeSoon() {
|
|
265
|
+
setTimeout(() => close());
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function onKeydown(event: KeyboardEvent) {
|
|
269
|
+
if (!open.value) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (event.key === 'Escape') {
|
|
274
|
+
close(true);
|
|
275
|
+
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const step = {
|
|
280
|
+
ArrowDown: 1,
|
|
281
|
+
ArrowUp: -1
|
|
282
|
+
}[event.key];
|
|
283
|
+
|
|
284
|
+
if (!step) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
|
|
290
|
+
const list = Array.from(root.value?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? []);
|
|
291
|
+
const index = list.indexOf(document.activeElement as HTMLElement);
|
|
292
|
+
|
|
293
|
+
list[index < 0 && step < 0 ? list.length - 1 : (index + step + list.length) % list.length]?.focus();
|
|
294
|
+
}
|
|
123
295
|
|
|
124
|
-
|
|
296
|
+
// A null target is a click on a control that takes no focus (Safari buttons): not a way out.
|
|
297
|
+
function onFocusout(event: FocusEvent) {
|
|
298
|
+
const next = event.relatedTarget as Node | null;
|
|
125
299
|
|
|
126
|
-
|
|
300
|
+
if (open.value && next && !root.value?.contains(next)) {
|
|
301
|
+
close();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function onOutside(event: Event) {
|
|
306
|
+
if (open.value && !root.value?.contains(event.target as Node)) {
|
|
307
|
+
close();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
onMounted(() => document.addEventListener('pointerdown', onOutside));
|
|
312
|
+
onUnmounted(() => document.removeEventListener('pointerdown', onOutside));
|
|
313
|
+
watch(
|
|
314
|
+
() => page.value.relativePath,
|
|
315
|
+
() => close()
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
// The block stays for the menu even when the kicker itself is switched off.
|
|
127
319
|
const hidden = computed(
|
|
128
|
-
() => (!meta.value && !
|
|
320
|
+
() => (!meta.value && !available.value) || frontmatter.value.layout === 'home'
|
|
129
321
|
);
|
|
130
322
|
</script>
|
|
131
323
|
|
|
@@ -155,14 +347,97 @@ const hidden = computed(
|
|
|
155
347
|
</time>
|
|
156
348
|
</ClientOnly>
|
|
157
349
|
|
|
158
|
-
<
|
|
159
|
-
v-if="
|
|
160
|
-
|
|
161
|
-
class="ff-doc-meta-
|
|
162
|
-
|
|
163
|
-
@
|
|
350
|
+
<div
|
|
351
|
+
v-if="available"
|
|
352
|
+
ref="root"
|
|
353
|
+
class="ff-doc-meta-actions"
|
|
354
|
+
@keydown="onKeydown"
|
|
355
|
+
@focusout="onFocusout"
|
|
164
356
|
>
|
|
165
|
-
<
|
|
166
|
-
|
|
357
|
+
<div
|
|
358
|
+
class="ff-doc-meta-split"
|
|
359
|
+
:class="{ copied }"
|
|
360
|
+
>
|
|
361
|
+
<button
|
|
362
|
+
v-if="main"
|
|
363
|
+
type="button"
|
|
364
|
+
class="ff-doc-meta-main"
|
|
365
|
+
@click="main === 'link' ? copyLink() : copyMarkdown()"
|
|
366
|
+
>
|
|
367
|
+
<MetaIcon :d="copied ? icons.check : main === 'link' ? icons.link : icons.copy" />
|
|
368
|
+
{{ mainLabel }}
|
|
369
|
+
</button>
|
|
370
|
+
|
|
371
|
+
<button
|
|
372
|
+
v-if="!main || hasMenu"
|
|
373
|
+
ref="trigger"
|
|
374
|
+
type="button"
|
|
375
|
+
class="ff-doc-meta-toggle"
|
|
376
|
+
:class="{ open }"
|
|
377
|
+
aria-haspopup="menu"
|
|
378
|
+
:aria-expanded="open"
|
|
379
|
+
:aria-label="main ? labels.pageActions : undefined"
|
|
380
|
+
@click="toggle"
|
|
381
|
+
>
|
|
382
|
+
<template v-if="!main">
|
|
383
|
+
<MetaIcon :d="icons.share" />
|
|
384
|
+
{{ labels.share }}
|
|
385
|
+
</template>
|
|
386
|
+
<MetaIcon
|
|
387
|
+
class="ff-doc-meta-chevron"
|
|
388
|
+
:d="icons.chevron"
|
|
389
|
+
/>
|
|
390
|
+
</button>
|
|
391
|
+
</div>
|
|
392
|
+
|
|
393
|
+
<span
|
|
394
|
+
class="visually-hidden"
|
|
395
|
+
aria-live="polite"
|
|
396
|
+
>{{ message }}</span>
|
|
397
|
+
|
|
398
|
+
<div
|
|
399
|
+
v-if="open"
|
|
400
|
+
class="ff-doc-meta-menu"
|
|
401
|
+
role="menu"
|
|
402
|
+
>
|
|
403
|
+
<button
|
|
404
|
+
v-if="menuMarkdown"
|
|
405
|
+
type="button"
|
|
406
|
+
role="menuitem"
|
|
407
|
+
@click="copyMarkdown(); close(true)"
|
|
408
|
+
>
|
|
409
|
+
<MetaIcon :d="icons.copy" />
|
|
410
|
+
<span class="ff-doc-meta-menu-text">
|
|
411
|
+
{{ labels.copyMarkdown }}
|
|
412
|
+
<small>{{ labels.copyMarkdownHint }}</small>
|
|
413
|
+
</span>
|
|
414
|
+
</button>
|
|
415
|
+
|
|
416
|
+
<hr
|
|
417
|
+
v-if="menuMarkdown && shares.length"
|
|
418
|
+
role="separator"
|
|
419
|
+
>
|
|
420
|
+
|
|
421
|
+
<a
|
|
422
|
+
v-for="share in shares"
|
|
423
|
+
:key="share.id"
|
|
424
|
+
role="menuitem"
|
|
425
|
+
:href="share.href"
|
|
426
|
+
target="_blank"
|
|
427
|
+
rel="noopener noreferrer"
|
|
428
|
+
@click="closeSoon"
|
|
429
|
+
>
|
|
430
|
+
<MetaIcon
|
|
431
|
+
:d="brands[share.id]"
|
|
432
|
+
brand
|
|
433
|
+
/>
|
|
434
|
+
<span class="ff-doc-meta-menu-text">{{ format(labels.shareOn, share.name) }}</span>
|
|
435
|
+
<MetaIcon
|
|
436
|
+
class="ff-doc-meta-external"
|
|
437
|
+
:d="icons.external"
|
|
438
|
+
/>
|
|
439
|
+
</a>
|
|
440
|
+
</div>
|
|
441
|
+
</div>
|
|
167
442
|
</div>
|
|
168
443
|
</template>
|
|
@@ -4,20 +4,15 @@ import {
|
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
7
|
+
import { resolveOption } from '../../node/options.js';
|
|
7
8
|
|
|
8
9
|
const { page, frontmatter, lang } = useData();
|
|
9
10
|
const options = useThemeOptions();
|
|
10
11
|
const labels = useLabels();
|
|
11
12
|
|
|
12
|
-
const config = computed(() =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!feedback || frontmatter.value.feedback === false) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return feedback === true ? {} : feedback;
|
|
20
|
-
});
|
|
13
|
+
const config = computed(() =>
|
|
14
|
+
resolveOption(options.value.feedback, frontmatter.value.feedback === false)
|
|
15
|
+
);
|
|
21
16
|
|
|
22
17
|
const question = computed(() => config.value?.question || labels.value.feedbackQuestion);
|
|
23
18
|
|