@frontfactory/vitepress-theme 1.8.0 → 1.9.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 +28 -0
- package/README.md +20 -7
- package/config.d.ts +4 -3
- package/config.js +58 -37
- package/dist/style.css +1 -1
- package/node/blog.d.ts +3 -0
- package/node/blog.js +19 -0
- package/node/llms.js +4 -3
- package/node/og.js +5 -6
- package/node/pages.js +14 -6
- package/node/rss.js +6 -9
- package/package.json +1 -1
- package/src/blog/posts.data.ts +3 -2
- package/src/components/FfBackToTop.vue +1 -1
- package/src/components/FfCopyStatus.vue +1 -1
- package/src/components/FfDocMeta.vue +300 -17
- 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 +4 -3
- package/src/composables/blog.ts +7 -4
- package/src/composables/copy.ts +36 -0
- package/src/composables/options.ts +9 -1
- package/src/composables/tabs.ts +2 -35
- 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 +6 -12
- package/src/styles/_content.scss +153 -63
- package/src/styles/_doc.scss +14 -24
- package/src/styles/_home.scss +11 -49
- package/src/styles/_mixins.scss +63 -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 +30 -4
- package/types/components/FfHeroActions.vue.d.ts +19 -0
- package/types/composables/copy.d.ts +6 -0
- package/types/composables/tabs.d.ts +0 -5
- package/types/internal.d.ts +1 -0
- package/types/types.d.ts +28 -4
package/node/og.js
CHANGED
|
@@ -2,9 +2,7 @@ import {
|
|
|
2
2
|
mkdir, readFile, writeFile
|
|
3
3
|
} from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
ogOptions, ogSlug, readPages
|
|
7
|
-
} from './pages.js';
|
|
5
|
+
import { ogOptions, ogSlug } from './pages.js';
|
|
8
6
|
|
|
9
7
|
const WIDTH = 1200;
|
|
10
8
|
const HEIGHT = 630;
|
|
@@ -104,8 +102,9 @@ function card({ siteTitle, title, description, family }) {
|
|
|
104
102
|
* so parallelism would only add memory.
|
|
105
103
|
*
|
|
106
104
|
* @param {import('vitepress').SiteConfig} siteConfig
|
|
105
|
+
* @param {Awaited<ReturnType<typeof import('./pages.js').readPages>>} allPages Pages read once by the caller.
|
|
107
106
|
*/
|
|
108
|
-
export async function generateOg(siteConfig) {
|
|
107
|
+
export async function generateOg(siteConfig, allPages) {
|
|
109
108
|
const { fonts } = ogOptions(siteConfig);
|
|
110
109
|
let satori;
|
|
111
110
|
let Resvg;
|
|
@@ -135,7 +134,7 @@ export async function generateOg(siteConfig) {
|
|
|
135
134
|
recursive: true
|
|
136
135
|
});
|
|
137
136
|
|
|
138
|
-
for (const { page, data, title, description } of
|
|
137
|
+
for (const { page, data, title, description } of allPages) {
|
|
139
138
|
if (data.og === 'false') {
|
|
140
139
|
continue;
|
|
141
140
|
}
|
|
@@ -152,7 +151,7 @@ export async function generateOg(siteConfig) {
|
|
|
152
151
|
});
|
|
153
152
|
|
|
154
153
|
await writeFile(
|
|
155
|
-
join(dir, `${ogSlug(page)}.png`),
|
|
154
|
+
join(dir, `${ogSlug(siteConfig.rewrites?.map?.[page] ?? page)}.png`),
|
|
156
155
|
new Resvg(svg).render().asPng()
|
|
157
156
|
);
|
|
158
157
|
}
|
package/node/pages.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
|
|
@@ -85,6 +86,16 @@ export function hostnameOf(siteConfig, explicit) {
|
|
|
85
86
|
return hostname?.replace(/\/+$/, '');
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Whether a page has a source file on disk. Dynamic routes and generated pages do not.
|
|
91
|
+
*
|
|
92
|
+
* @param {import('vitepress').SiteConfig} siteConfig
|
|
93
|
+
* @param {string} page Path relative to `srcDir`.
|
|
94
|
+
*/
|
|
95
|
+
export function hasSource(siteConfig, page) {
|
|
96
|
+
return existsSync(join(siteConfig.srcDir, page));
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
/**
|
|
89
100
|
* Every Markdown page of the site, source read and frontmatter parsed. `404.md` is left out.
|
|
90
101
|
*
|
|
@@ -98,15 +109,12 @@ export async function readPages(siteConfig) {
|
|
|
98
109
|
continue;
|
|
99
110
|
}
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
source = await readFile(join(siteConfig.srcDir, page), 'utf8');
|
|
105
|
-
} catch {
|
|
106
|
-
// Dynamic route or generated page: no source to read.
|
|
112
|
+
// Dynamic route or generated page: no source to read.
|
|
113
|
+
if (!hasSource(siteConfig, page)) {
|
|
107
114
|
continue;
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
const source = await readFile(join(siteConfig.srcDir, page), 'utf8');
|
|
110
118
|
const { data, body } = parseSource(source);
|
|
111
119
|
const heading = /^#\s+(.+)$/m.exec(body)?.[1].trim();
|
|
112
120
|
|
package/node/rss.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
/** Blog directory, without a slash at either end. */
|
|
6
|
-
export function blogDir(ff) {
|
|
7
|
-
return (ff.blog?.dir ?? 'blog').replace(/^\/+|\/+$/g, '');
|
|
8
|
-
}
|
|
3
|
+
import { blogDir, hasValidDate } from './blog.js';
|
|
4
|
+
import { hostnameOf } from './pages.js';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Writes `feed.xml`, an RSS 2.0 feed of the blog posts (dated pages under the blog directory,
|
|
@@ -13,8 +9,9 @@ export function blogDir(ff) {
|
|
|
13
9
|
* actually requested.
|
|
14
10
|
*
|
|
15
11
|
* @param {import('vitepress').SiteConfig} siteConfig
|
|
12
|
+
* @param {Awaited<ReturnType<typeof import('./pages.js').readPages>>} allPages Pages read once by the caller.
|
|
16
13
|
*/
|
|
17
|
-
export async function generateRss(siteConfig) {
|
|
14
|
+
export async function generateRss(siteConfig, allPages) {
|
|
18
15
|
const ff = siteConfig.site.themeConfig.ff;
|
|
19
16
|
const rss = typeof ff.blog.rss === 'object' ? ff.blog.rss : {};
|
|
20
17
|
const hostname = hostnameOf(siteConfig, rss.hostname);
|
|
@@ -49,8 +46,8 @@ export async function generateRss(siteConfig) {
|
|
|
49
46
|
}
|
|
50
47
|
});
|
|
51
48
|
|
|
52
|
-
const posts =
|
|
53
|
-
.filter(({ page, data }) => page.startsWith(`${dir}/`) && page !== `${dir}/index.md` && data.date)
|
|
49
|
+
const posts = allPages
|
|
50
|
+
.filter(({ page, data }) => page.startsWith(`${dir}/`) && page !== `${dir}/index.md` && hasValidDate(data.date))
|
|
54
51
|
.sort((a, b) => new Date(b.data.date) - new Date(a.data.date));
|
|
55
52
|
|
|
56
53
|
for (const { url, title: name, data } of posts) {
|
package/package.json
CHANGED
package/src/blog/posts.data.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContentLoader, type LoaderModule } from 'vitepress';
|
|
2
2
|
import type { ThemeConfig } from '../types.ts';
|
|
3
|
+
import { blogDir, hasValidDate } from '../../node/blog.js';
|
|
3
4
|
|
|
4
5
|
export interface Post {
|
|
5
6
|
url: string
|
|
@@ -20,7 +21,7 @@ export { data };
|
|
|
20
21
|
// reads it the same way), which is where the blog directory is read from.
|
|
21
22
|
const { site } = (globalThis as unknown as { VITEPRESS_CONFIG: { site: { themeConfig?: ThemeConfig } } })
|
|
22
23
|
.VITEPRESS_CONFIG;
|
|
23
|
-
const dir = (site.themeConfig?.ff
|
|
24
|
+
const dir = blogDir(site.themeConfig?.ff);
|
|
24
25
|
|
|
25
26
|
// Annotated so the emitted declaration doesn't reference VitePress's private `GlobOptions` (TS4082).
|
|
26
27
|
const loader: LoaderModule<Post[]> = createContentLoader([
|
|
@@ -30,7 +31,7 @@ const loader: LoaderModule<Post[]> = createContentLoader([
|
|
|
30
31
|
includeSrc: true,
|
|
31
32
|
transform(raw) {
|
|
32
33
|
return raw
|
|
33
|
-
.filter(({ frontmatter }) => frontmatter.date)
|
|
34
|
+
.filter(({ frontmatter }) => hasValidDate(frontmatter.date))
|
|
34
35
|
.map(({ url, src, frontmatter }): Post => ({
|
|
35
36
|
url,
|
|
36
37
|
title: frontmatter.title || /^#\s+(.+)$/m.exec(src ?? '')?.[1].trim() || url,
|
|
@@ -11,7 +11,7 @@ const labels = useLabels();
|
|
|
11
11
|
|
|
12
12
|
// The visible text is the accessible name; the tooltip reuses the default theme's own option,
|
|
13
13
|
// so a site that already localised its mobile return-to-top link gets this one for free.
|
|
14
|
-
const title = computed(() => theme.value.returnToTopLabel ??
|
|
14
|
+
const title = computed(() => theme.value.returnToTopLabel ?? labels.value.returnToTop);
|
|
15
15
|
|
|
16
16
|
const enabled = computed(() => options.value.backToTop !== false);
|
|
17
17
|
|
|
@@ -15,7 +15,7 @@ const BUTTON = 'div[class*="language-"] > button.copy';
|
|
|
15
15
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
16
16
|
|
|
17
17
|
function announce() {
|
|
18
|
-
message.value = labels.value.
|
|
18
|
+
message.value = labels.value.codeCopied;
|
|
19
19
|
|
|
20
20
|
clearTimeout(timer);
|
|
21
21
|
timer = setTimeout(() => (message.value = ''), 2000);
|
|
@@ -1,10 +1,10 @@
|
|
|
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
8
|
import { formatRelative } from '../composables/relativeTime';
|
|
9
9
|
import {
|
|
10
10
|
format, useLabels, useThemeOptions
|
|
@@ -111,21 +111,221 @@ const updatedAt = computed(() =>
|
|
|
111
111
|
);
|
|
112
112
|
|
|
113
113
|
// --------------------------------------------------------------------------------------------- //
|
|
114
|
-
//
|
|
114
|
+
// Page actions menu
|
|
115
115
|
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
116
|
+
// Copying the Markdown source needs `ffMarkdown`, put on the page data at build time by
|
|
117
|
+
// `ffTransformPageData`; without it that action stays out. `copyMarkdown` is the older spelling of
|
|
118
|
+
// `pageActions: { copyMarkdown: true }`.
|
|
118
119
|
// --------------------------------------------------------------------------------------------- //
|
|
119
120
|
|
|
121
|
+
type Network = 'x' | 'linkedin' | 'bluesky' | 'mastodon';
|
|
122
|
+
|
|
123
|
+
// 24px viewBox paths: the interface icons are stroked, the brand ones (Simple Icons, CC0) filled.
|
|
124
|
+
const icons = {
|
|
125
|
+
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',
|
|
126
|
+
check: 'M20 6 9 17l-5-5',
|
|
127
|
+
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',
|
|
128
|
+
share: 'M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13',
|
|
129
|
+
chevron: 'm6 9 6 6 6-6',
|
|
130
|
+
external: 'M7 7h10v10M7 17 17 7'
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const brands: Record<Network, string> = {
|
|
134
|
+
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',
|
|
135
|
+
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',
|
|
136
|
+
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',
|
|
137
|
+
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'
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const networks: Record<
|
|
141
|
+
Network,
|
|
142
|
+
{
|
|
143
|
+
name: string
|
|
144
|
+
url: (url: string, text: string, instance: string) => string
|
|
145
|
+
}
|
|
146
|
+
> = {
|
|
147
|
+
x: {
|
|
148
|
+
name: 'X',
|
|
149
|
+
url: (url, text) =>
|
|
150
|
+
`https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`
|
|
151
|
+
},
|
|
152
|
+
linkedin: {
|
|
153
|
+
name: 'LinkedIn',
|
|
154
|
+
url: (url) =>
|
|
155
|
+
`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`
|
|
156
|
+
},
|
|
157
|
+
bluesky: {
|
|
158
|
+
name: 'Bluesky',
|
|
159
|
+
url: (url, text) =>
|
|
160
|
+
`https://bsky.app/intent/compose?text=${encodeURIComponent(`${text} ${url}`)}`
|
|
161
|
+
},
|
|
162
|
+
mastodon: {
|
|
163
|
+
name: 'Mastodon',
|
|
164
|
+
url: (url, text, instance) =>
|
|
165
|
+
`https://${instance}/share?text=${encodeURIComponent(`${text} ${url}`)}`
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Renders one of the paths above.
|
|
170
|
+
const MetaIcon = (props: { d: string;
|
|
171
|
+
brand?: boolean }) =>
|
|
172
|
+
h(
|
|
173
|
+
'svg',
|
|
174
|
+
{
|
|
175
|
+
class: [
|
|
176
|
+
'ff-doc-meta-icon',
|
|
177
|
+
{
|
|
178
|
+
brand: props.brand
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
viewBox: '0 0 24 24',
|
|
182
|
+
'aria-hidden': 'true'
|
|
183
|
+
},
|
|
184
|
+
h('path', {
|
|
185
|
+
d: props.d
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
MetaIcon.props = [
|
|
190
|
+
'd',
|
|
191
|
+
'brand'
|
|
192
|
+
];
|
|
193
|
+
|
|
120
194
|
const markdown = computed(() => (page.value as { ffMarkdown?: string }).ffMarkdown ?? '');
|
|
121
195
|
|
|
122
|
-
const
|
|
196
|
+
const actions = computed(() => {
|
|
197
|
+
const { pageActions, copyMarkdown } = options.value;
|
|
198
|
+
const all = pageActions === true;
|
|
199
|
+
const config = typeof pageActions === 'object' ? pageActions : {};
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
markdown: (all || config.copyMarkdown || copyMarkdown === true) && !!markdown.value,
|
|
203
|
+
link: all || !!config.copyLink,
|
|
204
|
+
share: all ? (Object.keys(networks) as Network[]) : (config.share ?? []),
|
|
205
|
+
instance: config.mastodonInstance ?? 'mastodon.social'
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const available = computed(
|
|
210
|
+
() => actions.value.markdown || actions.value.link || actions.value.share.length > 0
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
// The main part of the split button copies the link, else the Markdown; with neither, the single
|
|
214
|
+
// "Share" trigger takes its place. The menu never repeats the main action.
|
|
215
|
+
const main = computed(() =>
|
|
216
|
+
actions.value.link ? 'link' : actions.value.markdown ? 'markdown' : null
|
|
217
|
+
);
|
|
218
|
+
const menuMarkdown = computed(() => main.value === 'link' && actions.value.markdown);
|
|
219
|
+
const hasMenu = computed(() => menuMarkdown.value || actions.value.share.length > 0);
|
|
220
|
+
|
|
221
|
+
// The page address without its query or hash, read on the client only.
|
|
222
|
+
function pageAddress() {
|
|
223
|
+
return window.location.origin + window.location.pathname;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const { copied: markdownCopied, copy: copyMarkdown } = useCopy(markdown);
|
|
227
|
+
const { copied: linkCopied, copy: copyLink } = useCopy(pageAddress);
|
|
228
|
+
|
|
229
|
+
const copied = computed(() => markdownCopied.value || linkCopied.value);
|
|
230
|
+
const message = computed(() =>
|
|
231
|
+
linkCopied.value ? labels.value.linkCopied : markdownCopied.value ? labels.value.heroCopied : ''
|
|
232
|
+
);
|
|
233
|
+
const mainLabel = computed(
|
|
234
|
+
() =>
|
|
235
|
+
message.value ||
|
|
236
|
+
(main.value === 'link' ? labels.value.copyLink : labels.value.copyMarkdown)
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const root = ref<HTMLElement>();
|
|
240
|
+
const trigger = ref<HTMLButtonElement>();
|
|
241
|
+
const open = ref(false);
|
|
242
|
+
const pageUrl = ref('');
|
|
243
|
+
|
|
244
|
+
const shares = computed(() =>
|
|
245
|
+
actions.value.share
|
|
246
|
+
.filter((id) => networks[id])
|
|
247
|
+
.map((id) => ({
|
|
248
|
+
id,
|
|
249
|
+
name: networks[id].name,
|
|
250
|
+
href: networks[id].url(pageUrl.value, page.value.title, actions.value.instance)
|
|
251
|
+
}))
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
function toggle() {
|
|
255
|
+
open.value = !open.value;
|
|
256
|
+
|
|
257
|
+
if (open.value) {
|
|
258
|
+
// Read on the client only, so the page renders the same on the server.
|
|
259
|
+
pageUrl.value = pageAddress();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function close(refocus = false) {
|
|
264
|
+
open.value = false;
|
|
265
|
+
|
|
266
|
+
if (refocus) {
|
|
267
|
+
trigger.value?.focus();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// A link is only followed once its handlers return, so the menu leaves after it.
|
|
272
|
+
function closeSoon() {
|
|
273
|
+
setTimeout(() => close());
|
|
274
|
+
}
|
|
123
275
|
|
|
124
|
-
|
|
276
|
+
function onKeydown(event: KeyboardEvent) {
|
|
277
|
+
if (!open.value) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
125
280
|
|
|
126
|
-
|
|
281
|
+
if (event.key === 'Escape') {
|
|
282
|
+
close(true);
|
|
283
|
+
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const step = {
|
|
288
|
+
ArrowDown: 1,
|
|
289
|
+
ArrowUp: -1
|
|
290
|
+
}[event.key];
|
|
291
|
+
|
|
292
|
+
if (!step) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
|
|
298
|
+
const list = Array.from(root.value?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? []);
|
|
299
|
+
const index = list.indexOf(document.activeElement as HTMLElement);
|
|
300
|
+
|
|
301
|
+
list[index < 0 && step < 0 ? list.length - 1 : (index + step + list.length) % list.length]?.focus();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// A null target is a click on a control that takes no focus (Safari buttons): not a way out.
|
|
305
|
+
function onFocusout(event: FocusEvent) {
|
|
306
|
+
const next = event.relatedTarget as Node | null;
|
|
307
|
+
|
|
308
|
+
if (open.value && next && !root.value?.contains(next)) {
|
|
309
|
+
close();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function onOutside(event: Event) {
|
|
314
|
+
if (open.value && !root.value?.contains(event.target as Node)) {
|
|
315
|
+
close();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
onMounted(() => document.addEventListener('pointerdown', onOutside));
|
|
320
|
+
onUnmounted(() => document.removeEventListener('pointerdown', onOutside));
|
|
321
|
+
watch(
|
|
322
|
+
() => page.value.relativePath,
|
|
323
|
+
() => close()
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
// The block stays for the menu even when the kicker itself is switched off.
|
|
127
327
|
const hidden = computed(
|
|
128
|
-
() => (!meta.value && !
|
|
328
|
+
() => (!meta.value && !available.value) || frontmatter.value.layout === 'home'
|
|
129
329
|
);
|
|
130
330
|
</script>
|
|
131
331
|
|
|
@@ -155,14 +355,97 @@ const hidden = computed(
|
|
|
155
355
|
</time>
|
|
156
356
|
</ClientOnly>
|
|
157
357
|
|
|
158
|
-
<
|
|
159
|
-
v-if="
|
|
160
|
-
|
|
161
|
-
class="ff-doc-meta-
|
|
162
|
-
|
|
163
|
-
@
|
|
358
|
+
<div
|
|
359
|
+
v-if="available"
|
|
360
|
+
ref="root"
|
|
361
|
+
class="ff-doc-meta-actions"
|
|
362
|
+
@keydown="onKeydown"
|
|
363
|
+
@focusout="onFocusout"
|
|
164
364
|
>
|
|
165
|
-
<
|
|
166
|
-
|
|
365
|
+
<div
|
|
366
|
+
class="ff-doc-meta-split"
|
|
367
|
+
:class="{ copied }"
|
|
368
|
+
>
|
|
369
|
+
<button
|
|
370
|
+
v-if="main"
|
|
371
|
+
type="button"
|
|
372
|
+
class="ff-doc-meta-main"
|
|
373
|
+
@click="main === 'link' ? copyLink() : copyMarkdown()"
|
|
374
|
+
>
|
|
375
|
+
<MetaIcon :d="copied ? icons.check : main === 'link' ? icons.link : icons.copy" />
|
|
376
|
+
{{ mainLabel }}
|
|
377
|
+
</button>
|
|
378
|
+
|
|
379
|
+
<button
|
|
380
|
+
v-if="!main || hasMenu"
|
|
381
|
+
ref="trigger"
|
|
382
|
+
type="button"
|
|
383
|
+
class="ff-doc-meta-toggle"
|
|
384
|
+
:class="{ open }"
|
|
385
|
+
aria-haspopup="menu"
|
|
386
|
+
:aria-expanded="open"
|
|
387
|
+
:aria-label="main ? labels.pageActions : undefined"
|
|
388
|
+
@click="toggle"
|
|
389
|
+
>
|
|
390
|
+
<template v-if="!main">
|
|
391
|
+
<MetaIcon :d="icons.share" />
|
|
392
|
+
{{ labels.share }}
|
|
393
|
+
</template>
|
|
394
|
+
<MetaIcon
|
|
395
|
+
class="ff-doc-meta-chevron"
|
|
396
|
+
:d="icons.chevron"
|
|
397
|
+
/>
|
|
398
|
+
</button>
|
|
399
|
+
</div>
|
|
400
|
+
|
|
401
|
+
<span
|
|
402
|
+
class="visually-hidden"
|
|
403
|
+
aria-live="polite"
|
|
404
|
+
>{{ message }}</span>
|
|
405
|
+
|
|
406
|
+
<div
|
|
407
|
+
v-if="open"
|
|
408
|
+
class="ff-doc-meta-menu"
|
|
409
|
+
role="menu"
|
|
410
|
+
>
|
|
411
|
+
<button
|
|
412
|
+
v-if="menuMarkdown"
|
|
413
|
+
type="button"
|
|
414
|
+
role="menuitem"
|
|
415
|
+
@click="copyMarkdown(); close(true)"
|
|
416
|
+
>
|
|
417
|
+
<MetaIcon :d="icons.copy" />
|
|
418
|
+
<span class="ff-doc-meta-menu-text">
|
|
419
|
+
{{ labels.copyMarkdown }}
|
|
420
|
+
<small>{{ labels.copyMarkdownHint }}</small>
|
|
421
|
+
</span>
|
|
422
|
+
</button>
|
|
423
|
+
|
|
424
|
+
<hr
|
|
425
|
+
v-if="menuMarkdown && shares.length"
|
|
426
|
+
role="separator"
|
|
427
|
+
>
|
|
428
|
+
|
|
429
|
+
<a
|
|
430
|
+
v-for="share in shares"
|
|
431
|
+
:key="share.id"
|
|
432
|
+
role="menuitem"
|
|
433
|
+
:href="share.href"
|
|
434
|
+
target="_blank"
|
|
435
|
+
rel="noopener noreferrer"
|
|
436
|
+
@click="closeSoon"
|
|
437
|
+
>
|
|
438
|
+
<MetaIcon
|
|
439
|
+
:d="brands[share.id]"
|
|
440
|
+
brand
|
|
441
|
+
/>
|
|
442
|
+
<span class="ff-doc-meta-menu-text">{{ format(labels.shareOn, share.name) }}</span>
|
|
443
|
+
<MetaIcon
|
|
444
|
+
class="ff-doc-meta-external"
|
|
445
|
+
:d="icons.external"
|
|
446
|
+
/>
|
|
447
|
+
</a>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
167
450
|
</div>
|
|
168
451
|
</template>
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
Comment, computed, Fragment, onBeforeUpdate, Text, useSlots, type VNode
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
|
-
import {
|
|
6
|
+
import { VPImage } from '../internal';
|
|
7
|
+
import FfHeroActions from './FfHeroActions.vue';
|
|
7
8
|
import FfHeroCommand from './FfHeroCommand.vue';
|
|
8
9
|
import type { HeroExtras, HeroMetaItem } from '../types';
|
|
9
10
|
import type { DefaultTheme } from 'vitepress/theme';
|
|
@@ -138,24 +139,14 @@ function hasInlineCommand() {
|
|
|
138
139
|
|
|
139
140
|
<slot name="home-hero-info-after" />
|
|
140
141
|
|
|
141
|
-
<
|
|
142
|
+
<FfHeroActions
|
|
142
143
|
v-if="hasActions && !hasPanel()"
|
|
143
|
-
|
|
144
|
+
:actions="actions!"
|
|
144
145
|
>
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
:key="action.link"
|
|
150
|
-
class="ff-btn"
|
|
151
|
-
:class="`ff-btn-${action.theme ?? 'brand'}`"
|
|
152
|
-
:href="normalizeLink(action.link)"
|
|
153
|
-
:target="action.target"
|
|
154
|
-
:rel="action.rel ?? (action.target === '_blank' ? 'noopener' : undefined)"
|
|
155
|
-
>
|
|
156
|
-
{{ action.text }}
|
|
157
|
-
</a>
|
|
158
|
-
</div>
|
|
146
|
+
<template #before>
|
|
147
|
+
<slot name="home-hero-actions-before-actions" />
|
|
148
|
+
</template>
|
|
149
|
+
</FfHeroActions>
|
|
159
150
|
|
|
160
151
|
<slot name="home-hero-actions-after" />
|
|
161
152
|
|
|
@@ -196,24 +187,14 @@ function hasInlineCommand() {
|
|
|
196
187
|
:bare="!hasActions"
|
|
197
188
|
/>
|
|
198
189
|
|
|
199
|
-
<
|
|
190
|
+
<FfHeroActions
|
|
200
191
|
v-if="hasActions"
|
|
201
|
-
|
|
192
|
+
:actions="actions!"
|
|
202
193
|
>
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
:key="action.link"
|
|
208
|
-
class="ff-btn"
|
|
209
|
-
:class="`ff-btn-${action.theme ?? 'brand'}`"
|
|
210
|
-
:href="normalizeLink(action.link)"
|
|
211
|
-
:target="action.target"
|
|
212
|
-
:rel="action.rel ?? (action.target === '_blank' ? 'noopener' : undefined)"
|
|
213
|
-
>
|
|
214
|
-
{{ action.text }}
|
|
215
|
-
</a>
|
|
216
|
-
</div>
|
|
194
|
+
<template #before>
|
|
195
|
+
<slot name="home-hero-actions-before-actions" />
|
|
196
|
+
</template>
|
|
197
|
+
</FfHeroActions>
|
|
217
198
|
</div>
|
|
218
199
|
</div>
|
|
219
200
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { isExternal, normalizeLink } from '../internal';
|
|
3
|
+
import type { HeroAction } from './FfHero.vue';
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
actions: HeroAction[]
|
|
7
|
+
}>();
|
|
8
|
+
|
|
9
|
+
// Like VPButton: an external link opens in a new tab and drops the referrer unless the action
|
|
10
|
+
// says otherwise.
|
|
11
|
+
function target(action: HeroAction) {
|
|
12
|
+
return action.target ?? (isExternal(action.link) ? '_blank' : undefined);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function rel(action: HeroAction) {
|
|
16
|
+
if (action.rel) {
|
|
17
|
+
return action.rel;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isExternal(action.link)) {
|
|
21
|
+
return 'noreferrer';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return target(action) === '_blank' ? 'noopener' : undefined;
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<div class="ff-hero-actions">
|
|
30
|
+
<slot name="before" />
|
|
31
|
+
|
|
32
|
+
<a
|
|
33
|
+
v-for="action in actions"
|
|
34
|
+
:key="action.link"
|
|
35
|
+
class="ff-btn"
|
|
36
|
+
:class="`ff-btn-${action.theme ?? 'brand'}`"
|
|
37
|
+
:href="normalizeLink(action.link)"
|
|
38
|
+
:target="target(action)"
|
|
39
|
+
:rel="rel(action)"
|
|
40
|
+
>
|
|
41
|
+
{{ action.text }}
|
|
42
|
+
</a>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, useId } from 'vue';
|
|
3
3
|
import { format, useLabels } from '../composables/options';
|
|
4
|
-
import { useCopy
|
|
4
|
+
import { useCopy } from '../composables/copy';
|
|
5
|
+
import { useTabs } from '../composables/tabs';
|
|
5
6
|
import type { HeroCommandTab } from '../types';
|
|
6
7
|
|
|
7
8
|
// Used from both hero panel positions (inline and beside the headline, see FfHero), which are
|
|
@@ -48,7 +49,7 @@ const { copied, copy } = useCopy(activeCommand);
|
|
|
48
49
|
<button
|
|
49
50
|
v-for="(tab, index) in tabs"
|
|
50
51
|
:id="`${id}-tab-${index}`"
|
|
51
|
-
:key="
|
|
52
|
+
:key="index"
|
|
52
53
|
type="button"
|
|
53
54
|
role="tab"
|
|
54
55
|
class="ff-hero-command-tab"
|