fix: search scrolling (#8792)

* Push basic stuff

* Push

* Bump site-kit
pull/8795/head
Puru Vijay 2 years ago committed by GitHub
parent 82cc48390c
commit 3d21b00fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -185,8 +185,8 @@ importers:
specifier: ^1.20.4
version: 1.20.4(svelte@packages+svelte)(vite@4.3.9)
'@sveltejs/site-kit':
specifier: 6.0.0-next.14
version: 6.0.0-next.14(@sveltejs/kit@1.20.4)(svelte@packages+svelte)
specifier: 6.0.0-next.16
version: 6.0.0-next.16(@sveltejs/kit@1.20.4)(svelte@packages+svelte)
'@sveltejs/vite-plugin-svelte':
specifier: ^2.4.1
version: 2.4.1(svelte@packages+svelte)(vite@4.3.9)
@ -1825,8 +1825,8 @@ packages:
svelte-local-storage-store: 0.4.0(svelte@packages+svelte)
dev: false
/@sveltejs/site-kit@6.0.0-next.14(@sveltejs/kit@1.20.4)(svelte@packages+svelte):
resolution: {integrity: sha512-KAQlX47fAL1LC1OCC/mQFDmSZyfX7zEK6/B1BEF6i265SN1OBwE1ZG4yrlQa5EaUVz8MIyjcvLqbikiqAWesTA==}
/@sveltejs/site-kit@6.0.0-next.16(@sveltejs/kit@1.20.4)(svelte@packages+svelte):
resolution: {integrity: sha512-GIP7nEC0J+5rzjCoLa6HIM0mGRKnt3rQz5xJcLEzua1GQRt9vkMiT/FGryr1s5baTNBIV7buWJgVQaz6pUat3w==}
peerDependencies:
'@sveltejs/kit': ^1.0.0
svelte: ^3.54.0 || ^4.0.0-next.1 || ^4.0.0

@ -30,7 +30,7 @@
"@resvg/resvg-js": "^2.4.1",
"@sveltejs/adapter-vercel": "^3.0.1",
"@sveltejs/kit": "^1.20.4",
"@sveltejs/site-kit": "6.0.0-next.14",
"@sveltejs/site-kit": "6.0.0-next.16",
"@sveltejs/vite-plugin-svelte": "^2.4.1",
"@types/marked": "^5.0.0",
"@types/node": "^20.3.1",

@ -99,29 +99,57 @@ export function get_docs_list(docs_data) {
}));
}
const titled = (str) =>
removeMarkdown(
escape(markedTransform(str, { paragraph: (txt) => txt }))
.replace(/<\/?code>/g, '')
.replace(/&#39;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/<(\/)?(em|b|strong|code)>/g, '')
);
/** @param {string} markdown */
function get_sections(markdown) {
const headingRegex = /^##\s+(.*)$/gm;
/** @type {import('./types').Section[]} */
const secondLevelHeadings = [];
let match;
const placeholders_rendered = replaceExportTypePlaceholders(markdown, modules);
while ((match = headingRegex.exec(placeholders_rendered)) !== null) {
secondLevelHeadings.push({
title: removeMarkdown(
escape(markedTransform(match[1], { paragraph: (txt) => txt }))
.replace(/<\/?code>/g, '')
.replace(/&#39;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/<(\/)?(em|b|strong|code)>/g, '')
),
slug: normalizeSlugify(match[1])
});
}
const lines = markdown.split('\n');
const root = /** @type {import('./types').Section} */ ({
title: 'Root',
slug: 'root',
sections: [],
breadcrumbs: [''],
text: ''
});
let currentNodes = [root];
lines.forEach((line) => {
const match = line.match(/^(#{2,4})\s(.*)/);
if (match) {
const level = match[1].length - 2;
const text = titled(match[2]);
const slug = normalizeSlugify(text);
// Prepare new node
/** @type {import('./types').Section} */
const newNode = {
title: text,
slug,
sections: [],
breadcrumbs: [...currentNodes[level].breadcrumbs, text],
text: ''
};
// Add the new node to the tree
currentNodes[level].sections.push(newNode);
// Prepare for potential children of the new node
currentNodes = currentNodes.slice(0, level + 1);
currentNodes.push(newNode);
} else if (line.trim() !== '') {
// Add non-heading line to the text of the current section
currentNodes[currentNodes.length - 1].text += line + '\n';
}
});
return secondLevelHeadings;
return root.sections;
}

@ -5,6 +5,8 @@ export interface Section {
slug: string;
// Currently, we are only going with 2 level headings, so this will be undefined. In future, we may want to support 3 levels, in which case this will be a list of sections
sections?: Section[];
breadcrumbs: string[];
text: string;
}
export type Category = {

@ -79,7 +79,7 @@ export function content() {
removeMarkdown(remove_TYPE(h2)),
removeMarkdown(remove_TYPE(h3))
],
href: get_href([slug, normalizeSlugify(h2), normalizeSlugify(h3)]),
href: get_href([slug, normalizeSlugify(h2) + '-' + normalizeSlugify(h3)]),
content: plaintext(lines.join('\n').trim()),
rank
});

Loading…
Cancel
Save