@ninjainfosys/site-kit 0.3.0 → 0.5.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/README.md +11 -6
- package/package.json +1 -1
- package/src/components/blog/PostCard.astro +1 -2
- package/src/integration.mjs +32 -3
- package/src/lib/blog-loader.ts +34 -0
- package/src/lib/blog.ts +10 -3
- package/src/lib/posts.ts +2 -2
- package/src/lib/rehype-posts.mjs +70 -0
- package/src/pages/blog/[slug].astro +20 -10
- package/src/pages/glossary/[slug].astro +3 -2
- package/src/pages/og/[...slug].png.ts +3 -1
- package/src/virtual.d.ts +5 -0
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ The package ships `.astro` and `.ts` source. The integration tells Vite to compi
|
|
|
37
37
|
|
|
38
38
|
| Page | Routes | Turn off with |
|
|
39
39
|
| --- | --- | --- |
|
|
40
|
-
| `blog` | `/blog`, `/blog/[slug]`, `/blog/page/[page]`, `/blog/tag/[tag]` | `pages: { blog: false }` |
|
|
40
|
+
| `blog` | `/blog`, `/blog/[slug]`, `/blog/page/[page]`, `/blog/tag/[tag]` | `pages: { blog: false }` (a site whose blog keeps its earlier layout supplies its own blog pages and still uses the kit's Pager, PostList and Topics) |
|
|
41
41
|
| `glossary` | `/glossary`, `/glossary/[slug]` | `pages: { glossary: false }` |
|
|
42
42
|
| `og` | `/og/[...slug].png` | `pages: { og: false }` |
|
|
43
43
|
| `rss` | `/rss.xml` | `pages: { rss: false }` |
|
|
@@ -49,13 +49,14 @@ The types are in `src/contract.ts`. A site provides these files under `src/`.
|
|
|
49
49
|
|
|
50
50
|
| File | What the kit reads |
|
|
51
51
|
| --- | --- |
|
|
52
|
-
| `config/site.ts` | `SITE_URL`, `SITE_NAME` (required). Optional: `COMPANY`, `CONTACT_EMAIL`, `CONTACT_PHONE_DISPLAY`, `CONTACT_PHONE_TEL`, `CONTACT_PHONE_JSONLD`, `OFFICE_LINE`, `LEGAL_ADDRESS`, `LEGAL_ADDRESS_LINE`, `SOCIAL_PROFILES
|
|
53
|
-
| `config/kit.ts` | `export const kit: SiteKit`. Required: `header`, `
|
|
52
|
+
| `config/site.ts` | `SITE_URL`, `SITE_NAME` (required). Optional: `COMPANY`, `CONTACT_EMAIL`, `CONTACT_PHONE_DISPLAY`, `CONTACT_PHONE_TEL`, `CONTACT_PHONE_JSONLD`, `OFFICE_LINE`, `LEGAL_ADDRESS`, `LEGAL_ADDRESS_LINE`, `SOCIAL_PROFILES` (an empty list is sent as `sameAs: []`), `PARENT_COMPANY_NAME`, `PARENT_COMPANY_URL`, `PARENT_COMPANY_ID`, `TAG_ACRONYMS` (shown in capitals in topic labels), `TAG_WORDS` (shown as written: `{ airfone: 'AirFone' }`). |
|
|
53
|
+
| `config/kit.ts` | `export const kit: SiteKit`. Required: `header`, `cta`, `og`, `llms`. Optional: `footer` (leave out when the site renders its own), `blog`, `seo`, `head`, `glossary`, `dashain`. `seo` can also replace the Organization data (`orgJsonLd`), the title rule (`titleFor`) and add WebPage data (`webPage`), an author meta and a robots meta. |
|
|
54
54
|
| `data/links.ts` | `productTags`, `productLink(slug)`, `productsForTags(tags)`, `solutionsForTags(tags)` (type `SiteLinks`). Return empty results on a site without products. |
|
|
55
|
-
| `layouts/Base.astro` | The site's layout. A site with nothing extra renders `@ninjainfosys/site-kit/layouts/Base.astro` and forwards its props. Slots on the kit layout: `head
|
|
55
|
+
| `layouts/Base.astro` | The site's layout. A site with nothing extra renders `@ninjainfosys/site-kit/layouts/Base.astro` and forwards its props. Slots on the kit layout: `head`, `head-end`, `header` and `footer` (the kit's Header and Footer are their fallbacks, so a site with its own footer passes it in `footer`), `scripts`, `body-end`. Write the slot elements with no whitespace between them or it leaks into `<main>`. |
|
|
56
56
|
| `styles/site.css` | Imports the site's fonts and tokens, then `@ninjainfosys/site-kit/styles/base.css` and `motion.css`, then rules only that site uses. |
|
|
57
|
+
| `components/BlogIndexExtra.astro` | Optional. Rendered under the pager of the blog front. |
|
|
57
58
|
| `data/glossary/terms/*.ts` | One `Term` per file, default export. Only when the glossary is on. |
|
|
58
|
-
| `content.config.ts` | The `blog` collection, with `postSchema` from `@ninjainfosys/site-kit/lib/blog-schema`. |
|
|
59
|
+
| `content.config.ts` | The `blog` collection, with `postSchema` from `@ninjainfosys/site-kit/lib/blog-schema` and `loader: blogLoader({ pattern: '**/*.md', base: './src/content/blog' })` from `@ninjainfosys/site-kit/lib/blog-loader`. The loader is Astro's glob loader that stores no drafts or scheduled posts in production, so their images and share cards are not built. |
|
|
59
60
|
|
|
60
61
|
Tokens the kit's CSS expects the site to define: `--canvas --surface --subtle --line --ink --ink-muted --brand --on-brand --link --lime --on-lime --stage --stage-ink --stage-muted --stage-line --error --space-* --radius-* --fast --slow --ease --font-*`. The header's featured link uses `--lime`; a site whose accent has another name aliases it.
|
|
61
62
|
|
|
@@ -63,7 +64,11 @@ Site code imports kit modules by package path, for example `@ninjainfosys/site-k
|
|
|
63
64
|
|
|
64
65
|
### Header and footer
|
|
65
66
|
|
|
66
|
-
The header is data. `kit.header` carries the logo, the utility strip, mega-menu groups with one featured link each, plain links, the bar action and the mobile sheet links. `action.google: true` draws Google's own sign-in button with the link as its fallback.
|
|
67
|
+
The header is data. `kit.header` carries the logo, the utility strip, mega-menu groups with one featured link each, plain links, the bar action and the mobile sheet links. `action.google: true` draws Google's own sign-in button with the link as its fallback. `logo.kind: 'mark'` draws a mark and a name (`logo.text`) instead of a lockup; `logo.text` on a lockup adds a wordmark beside it. Sites style their own logo with `.site-header .bar .logo` rules in `styles/site.css`, which win over the kit's scoped ones. The kit's CSS names its accent `--lime`; a site whose accent has another name aliases it. `kit.footer` carries the mark and the link columns; contact lines come from `config/site.ts`.
|
|
68
|
+
|
|
69
|
+
## Scheduled posts
|
|
70
|
+
|
|
71
|
+
A post whose `date` is after the build day (YYYY-MM-DD) is left out of every production page: the post, the blog front, tag and page lists, RSS, llms.txt, share cards, related and read-next, and so the sitemap. It appears on a rebuild on or after its date. This works like the glossary's `published` date. `SHOW_SCHEDULED=1` shows scheduled posts in a build, and the dev server always shows them (and drafts). Drafts stay out of production. Posts on the same day are ordered by id, so a build does not depend on cache state.
|
|
67
72
|
|
|
68
73
|
## Commands
|
|
69
74
|
|
package/package.json
CHANGED
|
@@ -6,8 +6,7 @@ const { post, big = false, level = 'h2' } = Astro.props;
|
|
|
6
6
|
const d = post.data;
|
|
7
7
|
const H = level;
|
|
8
8
|
---
|
|
9
|
-
<article class:list={['card', { big, pic: !!d.cover }]}>
|
|
10
|
-
{d.cover && (
|
|
9
|
+
<article class:list={['card', { big, pic: !!d.cover }]}>{d.cover && ' '}{d.cover && (
|
|
11
10
|
<div class="thumb">
|
|
12
11
|
<Image src={d.cover} alt="" widths={big ? [600, 900, 1200] : [400, 600, 800]} sizes={big ? '(max-width: 900px) 100vw, 1200px' : '(max-width: 600px) 100vw, 400px'} loading={big ? 'eager' : 'lazy'} />
|
|
13
12
|
</div>
|
package/src/integration.mjs
CHANGED
|
@@ -4,9 +4,11 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { rehypeFigures } from './lib/rehype-figures.mjs';
|
|
7
|
+
import { rehypeTables, rehypeUnlinkHidden } from './lib/rehype-posts.mjs';
|
|
7
8
|
|
|
8
9
|
const PACKAGE = '@ninjainfosys/site-kit';
|
|
9
10
|
const BLOG_IMAGES = 'virtual:site-kit/blog-images';
|
|
11
|
+
const HIDDEN_POSTS = 'virtual:site-kit/hidden-posts';
|
|
10
12
|
const IMAGE = /\.(jpe?g|png|webp|avif)$/i;
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -15,6 +17,27 @@ const IMAGE = /\.(jpe?g|png|webp|avif)$/i;
|
|
|
15
17
|
* with no post yet) into dist; this lists only posts that ship. The dev server
|
|
16
18
|
* lists every post so drafts can be reviewed.
|
|
17
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* Which posts ship. Drafts and posts dated after the build day are hidden in a
|
|
22
|
+
* build (SHOW_SCHEDULED=1 keeps scheduled ones); the dev server hides none.
|
|
23
|
+
*/
|
|
24
|
+
function postStatus(root, dev) {
|
|
25
|
+
const dir = join(root, 'src/content/blog');
|
|
26
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
27
|
+
const showScheduled = process.env.SHOW_SCHEDULED === '1';
|
|
28
|
+
const shipping = [];
|
|
29
|
+
const hidden = [];
|
|
30
|
+
if (!existsSync(dir)) return { shipping, hidden };
|
|
31
|
+
for (const f of readdirSync(dir).filter((x) => x.endsWith('.md'))) {
|
|
32
|
+
const fm = readFileSync(join(dir, f), 'utf8').match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1] ?? '';
|
|
33
|
+
const date = fm.match(/^date:\s*["']?(\d{4}-\d{2}-\d{2})/m)?.[1];
|
|
34
|
+
const draft = /^draft:\s*true\s*$/m.test(fm);
|
|
35
|
+
const scheduled = !showScheduled && !!date && date > today;
|
|
36
|
+
(!dev && (draft || scheduled) ? hidden : shipping).push(f.replace(/\.md$/, ''));
|
|
37
|
+
}
|
|
38
|
+
return { shipping, hidden };
|
|
39
|
+
}
|
|
40
|
+
|
|
18
41
|
function blogImages(root, dev) {
|
|
19
42
|
const posts = join(root, 'src/content/blog');
|
|
20
43
|
const assets = join(root, 'src/assets/blog');
|
|
@@ -62,14 +85,20 @@ export default function siteKit(options = {}) {
|
|
|
62
85
|
hooks: {
|
|
63
86
|
'astro:config:setup': ({ config, command, updateConfig, injectRoute }) => {
|
|
64
87
|
const root = fileURLToPath(config.root);
|
|
88
|
+
const status = postStatus(root, command === 'dev');
|
|
65
89
|
updateConfig({
|
|
66
|
-
markdown: { rehypePlugins: [rehypeFigures] },
|
|
90
|
+
markdown: { rehypePlugins: [rehypeFigures, rehypeTables, [rehypeUnlinkHidden, { hidden: status.hidden }]] },
|
|
67
91
|
vite: {
|
|
68
92
|
plugins: [
|
|
69
93
|
{
|
|
70
94
|
name: 'site-kit-blog-images',
|
|
71
|
-
resolveId: (id) => (id === BLOG_IMAGES ? `\0${
|
|
72
|
-
load: (id) =>
|
|
95
|
+
resolveId: (id) => (id === BLOG_IMAGES || id === HIDDEN_POSTS ? `\0${id}` : null),
|
|
96
|
+
load: (id) =>
|
|
97
|
+
id === `\0${BLOG_IMAGES}`
|
|
98
|
+
? blogImages(root, command === 'dev')
|
|
99
|
+
: id === `\0${HIDDEN_POSTS}`
|
|
100
|
+
? `export default ${JSON.stringify(status.hidden)};\n`
|
|
101
|
+
: null,
|
|
73
102
|
},
|
|
74
103
|
],
|
|
75
104
|
resolve: {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The blog collection's loader: Astro's glob loader, minus the entries that
|
|
2
|
+
// production leaves out (drafts and posts scheduled for later). They are never
|
|
3
|
+
// stored, so their cover and body images are not built into dist. The dev
|
|
4
|
+
// server keeps every entry.
|
|
5
|
+
import { glob } from 'astro/loaders';
|
|
6
|
+
import type { Loader } from 'astro/loaders';
|
|
7
|
+
import { isScheduled } from './blog';
|
|
8
|
+
|
|
9
|
+
type GlobOptions = Parameters<typeof glob>[0];
|
|
10
|
+
|
|
11
|
+
export function blogLoader(options: GlobOptions): Loader {
|
|
12
|
+
const inner = glob(options);
|
|
13
|
+
return {
|
|
14
|
+
...inner,
|
|
15
|
+
name: 'site-kit-blog',
|
|
16
|
+
async load(context) {
|
|
17
|
+
if (!import.meta.env.PROD) return inner.load(context);
|
|
18
|
+
const store = new Proxy(context.store, {
|
|
19
|
+
get(target, prop) {
|
|
20
|
+
const value = Reflect.get(target, prop, target);
|
|
21
|
+
if (prop === 'set') {
|
|
22
|
+
return (entry: { id: string; data: { draft?: boolean; date: Date } }) => {
|
|
23
|
+
const data = entry.data;
|
|
24
|
+
if (data.draft || isScheduled({ id: entry.id, data: { ...data, title: '', tags: [], draft: false } })) return false;
|
|
25
|
+
return (value as (e: unknown) => boolean).call(target, entry);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return inner.load({ ...context, store });
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/lib/blog.ts
CHANGED
|
@@ -11,9 +11,16 @@ export interface PostLike {
|
|
|
11
11
|
data: { title: string; date: Date; updated?: Date; tags: string[]; draft: boolean; pillar?: boolean };
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const day = (d: Date) => d.toISOString().slice(0, 10);
|
|
15
|
+
const showScheduled = typeof process !== 'undefined' && process.env.SHOW_SCHEDULED === '1';
|
|
16
|
+
/** A post dated after the build day stays out of the build until a rebuild on or after that day. SHOW_SCHEDULED=1 shows it. */
|
|
17
|
+
export const isScheduled = (p: PostLike) => !showScheduled && day(p.data.date) > day(new Date());
|
|
18
|
+
/** Newest first; posts on the same day keep a fixed order by id, so builds do not depend on cache state. */
|
|
19
|
+
export const byNewest = <T extends PostLike>(a: T, b: T) => b.data.date.getTime() - a.data.date.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
20
|
+
|
|
21
|
+
/** Published posts, newest first. Drafts and scheduled posts never reach pages, sitemap or RSS. */
|
|
15
22
|
export function published<T extends PostLike>(posts: T[]): T[] {
|
|
16
|
-
return posts.filter((p) => !p.data.draft
|
|
23
|
+
return posts.filter((p) => !p.data.draft && !isScheduled(p)).sort(byNewest);
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export function byTag<T extends PostLike>(posts: T[], tag: string): T[] {
|
|
@@ -61,7 +68,7 @@ export function related<T extends PostLike>(posts: T[], post: T, n = 3): T[] {
|
|
|
61
68
|
.filter((p) => p.id !== post.id)
|
|
62
69
|
.map((p) => ({ p, score: p.data.tags.filter((t) => post.data.tags.includes(t)).length }))
|
|
63
70
|
.filter((x) => x.score > 0)
|
|
64
|
-
.sort((a, b) => b.score - a.score ||
|
|
71
|
+
.sort((a, b) => b.score - a.score || byNewest(a.p, b.p))
|
|
65
72
|
.slice(0, n)
|
|
66
73
|
.map((x) => x.p);
|
|
67
74
|
}
|
package/src/lib/posts.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCollection, type CollectionEntry } from 'astro:content';
|
|
2
|
-
import { published } from './blog';
|
|
2
|
+
import { byNewest, isScheduled, published } from './blog';
|
|
3
3
|
|
|
4
4
|
export type Post = CollectionEntry<'blog'>;
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ export type Post = CollectionEntry<'blog'>;
|
|
|
9
9
|
*/
|
|
10
10
|
export async function posts(): Promise<Post[]> {
|
|
11
11
|
const all = await getCollection('blog');
|
|
12
|
-
if (import.meta.env.DEV) return all.sort(
|
|
12
|
+
if (import.meta.env.DEV) return all.sort(byNewest);
|
|
13
13
|
return published(all);
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Rehype steps for post bodies.
|
|
2
|
+
//
|
|
3
|
+
// rehypeTables wraps each table in a scroll box (so the page never scrolls
|
|
4
|
+
// sideways) and marks the columns of mostly numbers and prices with class
|
|
5
|
+
// `num`, which the post styles right-align.
|
|
6
|
+
//
|
|
7
|
+
// rehypeUnlinkHidden turns a link to /blog/<slug> into plain text when that
|
|
8
|
+
// post is a draft or scheduled for later, so a shipping page never links to a
|
|
9
|
+
// page that is not built. Links to posts that do not exist are left alone.
|
|
10
|
+
|
|
11
|
+
const NUM = /^[~≈<>+]?\s*(?:Rs\.?|NPR|US\$|\$)?\s*\d[\d,.]*\s*(?:%|[kKmM]\b|MB|GB|TB|Mbps|MP|days?|hrs?|months?|years?)?(?:\s*(?:–|-|to)\s*(?:Rs\.?|NPR|\$)?\s*\d[\d,.]*\s*(?:%|[kKmM]\b|MB|GB|TB|MP|days?)?)?(?:\s*\/\s*\w+)?$/i;
|
|
12
|
+
|
|
13
|
+
const textOf = (n) => (n.type === 'text' ? n.value : (n.children ?? []).map(textOf).join(''));
|
|
14
|
+
const isEl = (n, tag) => n.type === 'element' && n.tagName === tag;
|
|
15
|
+
const rowsOf = (table) => {
|
|
16
|
+
const rows = [];
|
|
17
|
+
const walk = (n) => { for (const c of n.children ?? []) { if (isEl(c, 'tr')) rows.push(c); else walk(c); } };
|
|
18
|
+
walk(table);
|
|
19
|
+
return rows;
|
|
20
|
+
};
|
|
21
|
+
const cellsOf = (tr) => (tr.children ?? []).filter((c) => isEl(c, 'td') || isEl(c, 'th'));
|
|
22
|
+
const addClass = (n, name) => {
|
|
23
|
+
const cur = n.properties?.className;
|
|
24
|
+
n.properties = { ...n.properties, className: [...(Array.isArray(cur) ? cur : cur ? [String(cur)] : []), name] };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function markNumbers(table) {
|
|
28
|
+
const body = rowsOf(table).filter((r) => cellsOf(r).some((c) => isEl(c, 'td')));
|
|
29
|
+
if (body.length < 2) return;
|
|
30
|
+
const cols = Math.max(...body.map((r) => cellsOf(r).length));
|
|
31
|
+
const numeric = new Set();
|
|
32
|
+
for (let i = 1; i < cols; i++) {
|
|
33
|
+
const texts = body.map((r) => textOf(cellsOf(r)[i] ?? { type: 'text', value: '' }).trim()).filter(Boolean);
|
|
34
|
+
if (texts.length >= 2 && texts.filter((t) => NUM.test(t)).length / texts.length >= 0.6) numeric.add(i);
|
|
35
|
+
}
|
|
36
|
+
if (!numeric.size) return;
|
|
37
|
+
for (const r of rowsOf(table)) cellsOf(r).forEach((c, i) => numeric.has(i) && addClass(c, 'num'));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function rehypeTables() {
|
|
41
|
+
const walk = (node) => {
|
|
42
|
+
if (!node.children) return;
|
|
43
|
+
node.children = node.children.map((child) => {
|
|
44
|
+
if (isEl(child, 'table')) {
|
|
45
|
+
markNumbers(child);
|
|
46
|
+
return { type: 'element', tagName: 'div', properties: { className: ['table-scroll'] }, children: [child] };
|
|
47
|
+
}
|
|
48
|
+
walk(child);
|
|
49
|
+
return child;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
return (tree) => walk(tree);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function rehypeUnlinkHidden(options = {}) {
|
|
56
|
+
const hidden = new Set(options.hidden ?? []);
|
|
57
|
+
const slugOf = (href) => {
|
|
58
|
+
const m = String(href ?? '').match(/^(?:https?:\/\/[^/]+)?\/blog\/([^/?#]+)\/?(?:[?#].*)?$/);
|
|
59
|
+
return m ? m[1] : null;
|
|
60
|
+
};
|
|
61
|
+
const walk = (node) => {
|
|
62
|
+
if (!node.children) return;
|
|
63
|
+
node.children = node.children.flatMap((child) => {
|
|
64
|
+
walk(child);
|
|
65
|
+
if (hidden.size && isEl(child, 'a') && hidden.has(slugOf(child.properties?.href))) return child.children ?? [];
|
|
66
|
+
return [child];
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return (tree) => walk(tree);
|
|
70
|
+
}
|
|
@@ -77,7 +77,7 @@ const readNext = (next.length ? next : all.filter((p) => p.id !== post.id)).slic
|
|
|
77
77
|
<h1 class="title" data-enter>{d.title}</h1>
|
|
78
78
|
<p class="meta" data-enter>
|
|
79
79
|
<time datetime={d.date.toISOString()}>{fmtDate(d.date)}</time>
|
|
80
|
-
{d.updated && <> · Updated <time datetime={d.updated.toISOString()}>{fmtDate(d.updated)}</time></>}
|
|
80
|
+
{d.updated && d.updated.toISOString().slice(0, 10) > d.date.toISOString().slice(0, 10) && <> · Updated <time datetime={d.updated.toISOString()}>{fmtDate(d.updated)}</time></>}
|
|
81
81
|
<> · {minutes} min read</>
|
|
82
82
|
{d.draft && <span class="draft"> · Draft, not published</span>}
|
|
83
83
|
</p>
|
|
@@ -154,14 +154,6 @@ const readNext = (next.length ? next : all.filter((p) => p.id !== post.id)).slic
|
|
|
154
154
|
</Base>
|
|
155
155
|
|
|
156
156
|
<script>
|
|
157
|
-
// Wide tables scroll inside their own box instead of the page.
|
|
158
|
-
document.querySelectorAll('.prose table').forEach((t) => {
|
|
159
|
-
const box = document.createElement('div');
|
|
160
|
-
box.className = 'table-scroll';
|
|
161
|
-
t.replaceWith(box);
|
|
162
|
-
box.append(t);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
157
|
// The side contents list marks the section being read.
|
|
166
158
|
const links = new Map([...document.querySelectorAll<HTMLAnchorElement>('[data-toc]')].map((a) => [a.dataset.toc!, a]));
|
|
167
159
|
if (links.size) {
|
|
@@ -217,7 +209,25 @@ const readNext = (next.length ? next : all.filter((p) => p.id !== post.id)).slic
|
|
|
217
209
|
.body :global(li + li) { margin-top: 0.35em; }
|
|
218
210
|
.body :global(h2) { font-weight: 600; font-size: 1.5rem; line-height: 1.25; margin: 1.8em 0 0.6em; scroll-margin-top: 104px; }
|
|
219
211
|
.body :global(h3) { font-weight: 600; font-size: 1.1875rem; line-height: 1.3; margin: 1.5em 0 0.4em; scroll-margin-top: 104px; }
|
|
220
|
-
|
|
212
|
+
|
|
213
|
+
/* Tables: a bordered box that scrolls sideways, a header and first column that stay in view. */
|
|
214
|
+
.body :global(.table-scroll) { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--line); border-radius: var(--radius-panel); }
|
|
215
|
+
.body :global(table) { width: 100%; border-collapse: separate; border-spacing: 0; font-family: var(--font-sans); font-size: 15px; line-height: 1.45; font-variant-numeric: tabular-nums; }
|
|
216
|
+
.body :global(th), .body :global(td) { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
|
|
217
|
+
.body :global(th) { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--ink); font-weight: 600; }
|
|
218
|
+
.body :global(td) { background: var(--canvas); }
|
|
219
|
+
.body :global(tbody tr:nth-child(even) td) { background: color-mix(in srgb, var(--surface) 50%, var(--canvas)); }
|
|
220
|
+
.body :global(tbody tr:hover td) { background: var(--subtle); }
|
|
221
|
+
.body :global(tbody tr:last-child td) { border-bottom: 0; }
|
|
222
|
+
.body :global(th:first-child), .body :global(td:first-child) { position: sticky; left: 0; }
|
|
223
|
+
.body :global(th:first-child) { z-index: 2; }
|
|
224
|
+
.body :global(td:first-child) { font-weight: 500; }
|
|
225
|
+
.body :global(th.num), .body :global(td.num) { text-align: right; white-space: nowrap; }
|
|
226
|
+
.body :global(td a), .body :global(th a) { color: var(--link); }
|
|
227
|
+
@media (max-width: 599px) {
|
|
228
|
+
.body :global(table) { font-size: 14px; }
|
|
229
|
+
.body :global(th), .body :global(td) { padding: 8px 12px; }
|
|
230
|
+
}
|
|
221
231
|
.body :global(figure) { margin: 1.6em 0; }
|
|
222
232
|
.body :global(figure img), .body :global(img) { display: block; width: 100%; height: auto; margin: 0; border-radius: var(--radius-panel); background: var(--surface); }
|
|
223
233
|
.body :global(figcaption) { margin-top: var(--space-2); font-size: 14px; line-height: 1.45; color: var(--ink-muted); }
|
|
@@ -6,6 +6,7 @@ import ArrowLeft from '@lucide/astro/icons/arrow-left';
|
|
|
6
6
|
import { glossary, termBySlug, type Term } from '../../lib/glossary';
|
|
7
7
|
import { productLink, productTags } from '@site/data/links';
|
|
8
8
|
import { posts } from '../../lib/posts';
|
|
9
|
+
import hiddenPosts from 'virtual:site-kit/hidden-posts';
|
|
9
10
|
import { breadcrumbJsonLd, definedTermJsonLd, faqJsonLd, termArticleJsonLd } from '../../lib/seo';
|
|
10
11
|
|
|
11
12
|
export function getStaticPaths() {
|
|
@@ -28,9 +29,9 @@ const words = [t.short, ...t.body, ...sections.flatMap((x) => [x.h, ...x.p, ...(
|
|
|
28
29
|
.map(strip).join(' ').split(/\s+/).length;
|
|
29
30
|
// Copy is ours; escape it, then turn [text](/path) into internal links.
|
|
30
31
|
const esc = (x: string) => x.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
31
|
-
// A link to a glossary term that is not live yet renders as plain text.
|
|
32
|
+
// A link to a glossary term that is not live yet, or to a post that is not built, renders as plain text.
|
|
32
33
|
const md = (x: string) => esc(x).replace(/\[([^\]]+)\]\((\/[^)\s]*)\)/g, (_, text, href) =>
|
|
33
|
-
href.startsWith('/glossary/') && !termBySlug(href.slice(10).split('#')[0]) ? text : `<a href="${href}">${text}</a>`);
|
|
34
|
+
(href.startsWith('/glossary/') && !termBySlug(href.slice(10).split('#')[0])) || (href.startsWith('/blog/') && hiddenPosts.includes(href.slice(6).split(/[#?]/)[0].replace(/\/$/, ''))) ? text : `<a href="${href}">${text}</a>`);
|
|
34
35
|
---
|
|
35
36
|
<Base
|
|
36
37
|
title={title}
|
|
@@ -10,6 +10,7 @@ import satori from 'satori';
|
|
|
10
10
|
// from trying to bundle its .node binary (which fails on Linux builders).
|
|
11
11
|
const { Resvg } = createRequire(import.meta.url)('@resvg/resvg-js') as typeof import('@resvg/resvg-js');
|
|
12
12
|
import { glossary } from '../../lib/glossary';
|
|
13
|
+
import { isScheduled } from '../../lib/blog';
|
|
13
14
|
import { SITE_NAME, SITE_URL, kit } from '../../config';
|
|
14
15
|
|
|
15
16
|
const { og } = kit;
|
|
@@ -22,7 +23,8 @@ const markImg = { type: 'img', props: { src: mark, width: og.mark.width, height:
|
|
|
22
23
|
const plate = og.mark.plate;
|
|
23
24
|
|
|
24
25
|
export async function getStaticPaths() {
|
|
25
|
-
|
|
26
|
+
// Drafts keep their cards; posts scheduled for later do not exist yet.
|
|
27
|
+
const posts = (await getCollection('blog')).filter((p) => !isScheduled(p));
|
|
26
28
|
const pages: { slug: string; title: string }[] = [
|
|
27
29
|
...og.pages(),
|
|
28
30
|
...(glossary.length ? [{ slug: 'glossary', title: kit.glossary.ogTitle }] : []),
|
package/src/virtual.d.ts
CHANGED
|
@@ -2,3 +2,8 @@ declare module 'virtual:site-kit/blog-images' {
|
|
|
2
2
|
const images: Record<string, { default: unknown }>;
|
|
3
3
|
export default images;
|
|
4
4
|
}
|
|
5
|
+
declare module 'virtual:site-kit/hidden-posts' {
|
|
6
|
+
/** Slugs of posts that exist but are not built (drafts, scheduled). Empty on the dev server. */
|
|
7
|
+
const slugs: string[];
|
|
8
|
+
export default slugs;
|
|
9
|
+
}
|