@frontfactory/vitepress-theme 1.6.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 +214 -0
- package/README.md +160 -8
- 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 +49 -26
- package/src/blog/posts.data.ts +46 -0
- package/src/components/FfBackToTop.vue +33 -10
- package/src/components/FfBanner.vue +42 -8
- package/src/components/FfCopyStatus.vue +64 -0
- package/src/components/FfDocMeta.vue +50 -46
- package/src/components/FfFeature.vue +18 -7
- package/src/components/FfFeedback.vue +96 -0
- package/src/components/FfFooter.vue +11 -5
- package/src/components/FfHero.vue +20 -10
- package/src/components/FfHeroCommand.vue +24 -27
- 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 +19 -14
- package/src/composables/relativeTime.ts +59 -0
- 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 +20 -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 +280 -12
- package/src/styles/_doc.scss +18 -5
- package/src/styles/_home.scss +37 -17
- package/src/styles/_motion.scss +22 -2
- 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 +75 -9
- package/src/styles/index.scss +2 -0
- package/src/types.ts +140 -2
- 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/og.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdir, readFile, writeFile
|
|
3
|
+
} from 'node:fs/promises';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
ogOptions, ogSlug, readPages
|
|
7
|
+
} from './pages.js';
|
|
8
|
+
|
|
9
|
+
const WIDTH = 1200;
|
|
10
|
+
const HEIGHT = 630;
|
|
11
|
+
|
|
12
|
+
// The default theme's light palette, so a card looks like the site it advertises.
|
|
13
|
+
const paper = '#fbfaf8';
|
|
14
|
+
const ink = '#17171c';
|
|
15
|
+
const muted = '#5c5c66';
|
|
16
|
+
const rule = '#d6d3cd';
|
|
17
|
+
const accent = '#2745cf';
|
|
18
|
+
|
|
19
|
+
/** Satori element, as a plain object: no JSX, no build step. */
|
|
20
|
+
const el = (type, style, children) => ({
|
|
21
|
+
type,
|
|
22
|
+
props: {
|
|
23
|
+
style,
|
|
24
|
+
children
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function card({ siteTitle, title, description, family }) {
|
|
29
|
+
const mono = {
|
|
30
|
+
fontFamily: family,
|
|
31
|
+
textTransform: 'uppercase',
|
|
32
|
+
letterSpacing: 4,
|
|
33
|
+
fontSize: 24,
|
|
34
|
+
color: muted
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return el('div', {
|
|
38
|
+
display: 'flex',
|
|
39
|
+
flexDirection: 'column',
|
|
40
|
+
justifyContent: 'space-between',
|
|
41
|
+
width: WIDTH,
|
|
42
|
+
height: HEIGHT,
|
|
43
|
+
boxSizing: 'border-box',
|
|
44
|
+
padding: 72,
|
|
45
|
+
background: paper,
|
|
46
|
+
fontFamily: family
|
|
47
|
+
}, [
|
|
48
|
+
el('div', {
|
|
49
|
+
display: 'flex',
|
|
50
|
+
alignItems: 'center',
|
|
51
|
+
gap: 16
|
|
52
|
+
}, [
|
|
53
|
+
el('div', {
|
|
54
|
+
width: 18,
|
|
55
|
+
height: 18,
|
|
56
|
+
background: accent
|
|
57
|
+
}),
|
|
58
|
+
el('div', mono, siteTitle)
|
|
59
|
+
]),
|
|
60
|
+
el('div', {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
flexDirection: 'column',
|
|
63
|
+
gap: 28
|
|
64
|
+
}, [
|
|
65
|
+
el('div', {
|
|
66
|
+
fontSize: title.length > 48 ? 60 : 76,
|
|
67
|
+
fontWeight: 700,
|
|
68
|
+
lineHeight: 1.1,
|
|
69
|
+
letterSpacing: -2,
|
|
70
|
+
color: ink
|
|
71
|
+
}, title),
|
|
72
|
+
...description ? [
|
|
73
|
+
el('div', {
|
|
74
|
+
fontSize: 32,
|
|
75
|
+
lineHeight: 1.4,
|
|
76
|
+
color: muted
|
|
77
|
+
}, description.length > 140 ? `${description.slice(0, 137)}...` : description)
|
|
78
|
+
] : []
|
|
79
|
+
]),
|
|
80
|
+
el('div', {
|
|
81
|
+
display: 'flex',
|
|
82
|
+
width: '100%',
|
|
83
|
+
height: 3,
|
|
84
|
+
flexShrink: 0
|
|
85
|
+
}, [
|
|
86
|
+
el('div', {
|
|
87
|
+
width: 160,
|
|
88
|
+
height: 3,
|
|
89
|
+
flexShrink: 0,
|
|
90
|
+
backgroundColor: accent
|
|
91
|
+
}),
|
|
92
|
+
el('div', {
|
|
93
|
+
flexGrow: 1,
|
|
94
|
+
height: 3,
|
|
95
|
+
backgroundColor: rule
|
|
96
|
+
})
|
|
97
|
+
])
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Renders one PNG per page into `outDir/og/`. `satori` and `@resvg/resvg-js` are optional peer
|
|
103
|
+
* dependencies, loaded only here. Pages are drawn one after the other: each render is CPU-bound,
|
|
104
|
+
* so parallelism would only add memory.
|
|
105
|
+
*
|
|
106
|
+
* @param {import('vitepress').SiteConfig} siteConfig
|
|
107
|
+
*/
|
|
108
|
+
export async function generateOg(siteConfig) {
|
|
109
|
+
const { fonts } = ogOptions(siteConfig);
|
|
110
|
+
let satori;
|
|
111
|
+
let Resvg;
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
[
|
|
115
|
+
{ default: satori },
|
|
116
|
+
{ Resvg }
|
|
117
|
+
] = await Promise.all([
|
|
118
|
+
import('satori'),
|
|
119
|
+
import('@resvg/resvg-js')
|
|
120
|
+
]);
|
|
121
|
+
} catch {
|
|
122
|
+
throw new Error('[vitepress-theme] `ff.og` needs `satori` and `@resvg/resvg-js`: run `npm install satori @resvg/resvg-js`.');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const loaded = await Promise.all(fonts.map(async ({ name, path, weight, style }) => ({
|
|
126
|
+
name,
|
|
127
|
+
data: await readFile(resolve(siteConfig.root ?? process.cwd(), path)),
|
|
128
|
+
weight,
|
|
129
|
+
style
|
|
130
|
+
})));
|
|
131
|
+
const { site } = siteConfig;
|
|
132
|
+
const dir = join(siteConfig.outDir, 'og');
|
|
133
|
+
|
|
134
|
+
await mkdir(dir, {
|
|
135
|
+
recursive: true
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
for (const { page, data, title, description } of await readPages(siteConfig)) {
|
|
139
|
+
if (data.og === 'false') {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const svg = await satori(card({
|
|
144
|
+
siteTitle: site.title,
|
|
145
|
+
title,
|
|
146
|
+
description: description || site.description,
|
|
147
|
+
family: loaded[0].name
|
|
148
|
+
}), {
|
|
149
|
+
width: WIDTH,
|
|
150
|
+
height: HEIGHT,
|
|
151
|
+
fonts: loaded
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await writeFile(
|
|
155
|
+
join(dir, `${ogSlug(page)}.png`),
|
|
156
|
+
new Resvg(svg).render().asPng()
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
package/node/pages.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads the few frontmatter keys the build helpers need. A full YAML parser would be a new
|
|
8
|
+
* dependency for what is, here, scalars and flat lists: `key: value`, `key: [a, b]` and block
|
|
9
|
+
* `- item` lists. Anything fancier (nested maps, multi-line strings) is left out on purpose.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} source
|
|
12
|
+
* @returns {{ data: Record<string, string | string[]>, body: string }}
|
|
13
|
+
*/
|
|
14
|
+
export function parseSource(source) {
|
|
15
|
+
const match = FRONTMATTER.exec(source);
|
|
16
|
+
const data = {};
|
|
17
|
+
|
|
18
|
+
if (!match) {
|
|
19
|
+
return {
|
|
20
|
+
data,
|
|
21
|
+
body: source.trim()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const unquote = (value) => value.trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
26
|
+
let list = null;
|
|
27
|
+
|
|
28
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
29
|
+
const item = /^\s+-\s+(.*)$/.exec(line);
|
|
30
|
+
|
|
31
|
+
if (item && list) {
|
|
32
|
+
list.push(unquote(item[1]));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const pair = /^([\w-]+):\s*(.*)$/.exec(line);
|
|
37
|
+
|
|
38
|
+
list = null;
|
|
39
|
+
|
|
40
|
+
if (!pair) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const [
|
|
45
|
+
, key,
|
|
46
|
+
value
|
|
47
|
+
] = pair;
|
|
48
|
+
|
|
49
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
50
|
+
data[key] = value.slice(1, -1).split(',').map(unquote).filter(Boolean);
|
|
51
|
+
} else if (value === '') {
|
|
52
|
+
list = data[key] = [];
|
|
53
|
+
} else {
|
|
54
|
+
data[key] = unquote(value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
data,
|
|
60
|
+
body: source.slice(match[0].length).trim()
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Public URL path of a page: honours `rewrites`, `cleanUrls` and `base`.
|
|
66
|
+
*
|
|
67
|
+
* @param {import('vitepress').SiteConfig} siteConfig
|
|
68
|
+
* @param {string} page Path relative to `srcDir`.
|
|
69
|
+
*/
|
|
70
|
+
export function pageUrl(siteConfig, page) {
|
|
71
|
+
const rewritten = siteConfig.rewrites?.map?.[page] ?? page;
|
|
72
|
+
let url = rewritten.replace(/\.md$/, '').replace(/(^|\/)index$/, '$1');
|
|
73
|
+
|
|
74
|
+
if (url && !url.endsWith('/') && !siteConfig.cleanUrls) {
|
|
75
|
+
url += '.html';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return `${siteConfig.site.base}${url}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Site hostname without a trailing slash, from an explicit value or the sitemap option. */
|
|
82
|
+
export function hostnameOf(siteConfig, explicit) {
|
|
83
|
+
const hostname = explicit ?? siteConfig.userConfig?.sitemap?.hostname;
|
|
84
|
+
|
|
85
|
+
return hostname?.replace(/\/+$/, '');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Every Markdown page of the site, source read and frontmatter parsed. `404.md` is left out.
|
|
90
|
+
*
|
|
91
|
+
* @param {import('vitepress').SiteConfig} siteConfig
|
|
92
|
+
*/
|
|
93
|
+
export async function readPages(siteConfig) {
|
|
94
|
+
const pages = [];
|
|
95
|
+
|
|
96
|
+
for (const page of siteConfig.pages) {
|
|
97
|
+
if (page === '404.md') {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let source;
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
source = await readFile(join(siteConfig.srcDir, page), 'utf8');
|
|
105
|
+
} catch {
|
|
106
|
+
// Dynamic route or generated page: no source to read.
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { data, body } = parseSource(source);
|
|
111
|
+
const heading = /^#\s+(.+)$/m.exec(body)?.[1].trim();
|
|
112
|
+
|
|
113
|
+
pages.push({
|
|
114
|
+
page,
|
|
115
|
+
data,
|
|
116
|
+
body,
|
|
117
|
+
url: pageUrl(siteConfig, page),
|
|
118
|
+
title: data.title || heading || (page === 'index.md'
|
|
119
|
+
? siteConfig.site.title
|
|
120
|
+
: page.replace(/\.md$/, '').split('/').pop()),
|
|
121
|
+
description: data.description || ''
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return pages;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Filename (without extension) of a page's generated image: its source path, flattened. */
|
|
129
|
+
export function ogSlug(page) {
|
|
130
|
+
return page.replace(/\.md$/, '').replace(/\//g, '-');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Settings of `ff.og`, validated. `satori` cannot draw without a font, and the image URL must be
|
|
135
|
+
* absolute for crawlers, so both are required: fail with a message that says what to add.
|
|
136
|
+
*/
|
|
137
|
+
export function ogOptions(siteConfig) {
|
|
138
|
+
const og = siteConfig.site.themeConfig?.ff?.og;
|
|
139
|
+
const hostname = hostnameOf(siteConfig, typeof og === 'object' ? og.hostname : undefined);
|
|
140
|
+
const fonts = typeof og === 'object' ? og.fonts ?? [] : [];
|
|
141
|
+
|
|
142
|
+
if (!fonts.length) {
|
|
143
|
+
throw new Error('[vitepress-theme] `ff.og` needs at least one font: set `ff.og.fonts` (TTF, OTF or WOFF files).');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!hostname) {
|
|
147
|
+
throw new Error('[vitepress-theme] `ff.og` needs an absolute address: set `ff.og.hostname` or `sitemap.hostname`.');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
fonts,
|
|
152
|
+
hostname
|
|
153
|
+
};
|
|
154
|
+
}
|
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,31 +36,50 @@
|
|
|
35
36
|
"./package.json": "./package.json"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@commitlint/
|
|
40
|
-
"@
|
|
41
|
-
"@front-factory/
|
|
42
|
-
"@
|
|
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",
|
|
44
|
+
"@magnesium/theme": "^5.3.0",
|
|
45
|
+
"@playwright/test": "^1.64.1",
|
|
46
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
43
47
|
"@semantic-release/changelog": "^7.0.0",
|
|
44
48
|
"@semantic-release/git": "^11.0.1",
|
|
45
|
-
"@semantic-release/github": "^12.0.9",
|
|
46
49
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
47
|
-
"eslint": "^10.
|
|
48
|
-
"eslint-plugin-vue": "^10.
|
|
50
|
+
"eslint": "^10.14.0",
|
|
51
|
+
"eslint-plugin-vue": "^10.12.0",
|
|
52
|
+
"feed": "^6.0.0",
|
|
49
53
|
"husky": "^9.1.7",
|
|
50
|
-
"sass": "^1.
|
|
54
|
+
"sass": "^1.107.1",
|
|
55
|
+
"satori": "^0.63.2",
|
|
51
56
|
"semantic-release": "^25.0.9",
|
|
52
|
-
"stylelint": "^16.
|
|
53
|
-
"typescript": "^
|
|
54
|
-
"typescript-eslint": "^8.
|
|
55
|
-
"vitepress": "^2.0.0-alpha.
|
|
56
|
-
"vue": "^3.5.
|
|
57
|
-
"vue-tsc": "^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"
|
|
58
63
|
},
|
|
59
64
|
"peerDependencies": {
|
|
65
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
66
|
+
"feed": "^6.0.0",
|
|
67
|
+
"satori": "^0.63.2",
|
|
68
|
+
"vite": "^8.2.1",
|
|
60
69
|
"vitepress": "^2.0.0-alpha.20",
|
|
61
70
|
"vue": "^3.5.0"
|
|
62
71
|
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@resvg/resvg-js": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"feed": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"satori": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
63
83
|
"keywords": [
|
|
64
84
|
"vitepress",
|
|
65
85
|
"vitepress-theme",
|
|
@@ -82,9 +102,12 @@
|
|
|
82
102
|
],
|
|
83
103
|
"files": [
|
|
84
104
|
"src",
|
|
85
|
-
"dist",
|
|
105
|
+
"dist/style.css",
|
|
106
|
+
"types",
|
|
107
|
+
"CHANGELOG.md",
|
|
86
108
|
"config.js",
|
|
87
|
-
"config.d.ts"
|
|
109
|
+
"config.d.ts",
|
|
110
|
+
"node"
|
|
88
111
|
],
|
|
89
112
|
"publishConfig": {
|
|
90
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';
|
|
@@ -17,25 +17,49 @@ const enabled = computed(() => options.value.backToTop !== false);
|
|
|
17
17
|
|
|
18
18
|
const visible = ref(false);
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function update() {
|
|
21
21
|
visible.value = window.scrollY > window.innerHeight;
|
|
22
22
|
}
|
|
23
23
|
|
|
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
|
+
|
|
24
36
|
function toTop() {
|
|
25
37
|
window.scrollTo({
|
|
26
38
|
top: 0,
|
|
27
|
-
behavior: 'smooth'
|
|
39
|
+
behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
|
|
28
40
|
});
|
|
29
41
|
}
|
|
30
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.
|
|
31
45
|
onMounted(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
});
|
|
35
61
|
});
|
|
36
62
|
});
|
|
37
|
-
|
|
38
|
-
onUnmounted(() => window.removeEventListener('scroll', onScroll));
|
|
39
63
|
</script>
|
|
40
64
|
|
|
41
65
|
<template>
|
|
@@ -45,8 +69,7 @@ onUnmounted(() => window.removeEventListener('scroll', onScroll));
|
|
|
45
69
|
type="button"
|
|
46
70
|
class="ff-to-top ff-label"
|
|
47
71
|
:class="{ 'is-visible': visible }"
|
|
48
|
-
:
|
|
49
|
-
:aria-hidden="!visible"
|
|
72
|
+
:inert="visible ? undefined : true"
|
|
50
73
|
:title="title"
|
|
51
74
|
@click="toTop"
|
|
52
75
|
>
|