This commit is contained in:
parent
84769f9ce4
commit
fd4bb61b5f
30 changed files with 355 additions and 156 deletions
|
|
@ -40,16 +40,11 @@ const postLastmodLookup = new Map(
|
|||
export default defineConfig({
|
||||
site: 'https://schmelczer.dev',
|
||||
trailingSlash: 'ignore',
|
||||
build: { inlineStylesheets: 'always' },
|
||||
redirects: {
|
||||
'/writing/': '/articles/',
|
||||
'/writing/[slug]': '/articles/[slug]',
|
||||
},
|
||||
integrations: [
|
||||
sitemap({
|
||||
filter: (page) => {
|
||||
const path = new URL(page).pathname;
|
||||
return !path.startsWith('/writing/') && path !== '/404/';
|
||||
return !/^\/tags\/[^/]+\/?$/.test(path) && path !== '/404/';
|
||||
},
|
||||
serialize(item) {
|
||||
const url = new URL(item.url);
|
||||
|
|
@ -93,7 +88,6 @@ export default defineConfig({
|
|||
behavior: 'append',
|
||||
properties: {
|
||||
className: ['heading-anchor'],
|
||||
ariaLabel: 'Permalink',
|
||||
},
|
||||
// Glyph rendered via CSS ::before so it doesn't leak into the TOC
|
||||
// when astro:content extracts heading.text from the rendered HTML.
|
||||
|
|
@ -110,11 +104,33 @@ export default defineConfig({
|
|||
return (tree) => {
|
||||
visit(tree, 'element', (node) => {
|
||||
if (!SCROLLABLE.has(node.tagName)) return;
|
||||
node.properties = node.properties ?? {};
|
||||
node.properties.tabindex = '0';
|
||||
});
|
||||
};
|
||||
},
|
||||
function rehypeLabelHeadingPermalinks() {
|
||||
function textOf(node) {
|
||||
if (!node) return '';
|
||||
if (node.type === 'text') return node.value ?? '';
|
||||
return (node.children ?? []).map(textOf).join('');
|
||||
}
|
||||
|
||||
return (tree) => {
|
||||
visit(tree, 'element', (node) => {
|
||||
if (!/^h[2-6]$/.test(node.tagName)) return;
|
||||
const headingText = textOf(node).trim();
|
||||
if (!headingText) return;
|
||||
|
||||
for (const child of node.children ?? []) {
|
||||
const className = child.properties?.className;
|
||||
const classes = Array.isArray(className) ? className : [className];
|
||||
if (child.tagName === 'a' && classes.includes('heading-anchor')) {
|
||||
child.properties.ariaLabel = `Permalink to ${headingText}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue