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

@ -30,7 +30,7 @@
"@resvg/resvg-js": "^2.4.1", "@resvg/resvg-js": "^2.4.1",
"@sveltejs/adapter-vercel": "^3.0.1", "@sveltejs/adapter-vercel": "^3.0.1",
"@sveltejs/kit": "^1.20.4", "@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", "@sveltejs/vite-plugin-svelte": "^2.4.1",
"@types/marked": "^5.0.0", "@types/marked": "^5.0.0",
"@types/node": "^20.3.1", "@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 */ /** @param {string} markdown */
function get_sections(markdown) { function get_sections(markdown) {
const headingRegex = /^##\s+(.*)$/gm; const lines = markdown.split('\n');
/** @type {import('./types').Section[]} */ const root = /** @type {import('./types').Section} */ ({
const secondLevelHeadings = []; title: 'Root',
let match; slug: 'root',
sections: [],
const placeholders_rendered = replaceExportTypePlaceholders(markdown, modules); breadcrumbs: [''],
text: ''
while ((match = headingRegex.exec(placeholders_rendered)) !== null) { });
secondLevelHeadings.push({ let currentNodes = [root];
title: removeMarkdown(
escape(markedTransform(match[1], { paragraph: (txt) => txt })) lines.forEach((line) => {
.replace(/<\/?code>/g, '') const match = line.match(/^(#{2,4})\s(.*)/);
.replace(/&#39;/g, "'") if (match) {
.replace(/&quot;/g, '"') const level = match[1].length - 2;
.replace(/&lt;/g, '<') const text = titled(match[2]);
.replace(/&gt;/g, '>') const slug = normalizeSlugify(text);
.replace(/<(\/)?(em|b|strong|code)>/g, '')
), // Prepare new node
slug: normalizeSlugify(match[1]) /** @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; 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 // 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[]; sections?: Section[];
breadcrumbs: string[];
text: string;
} }
export type Category = { export type Category = {

@ -79,7 +79,7 @@ export function content() {
removeMarkdown(remove_TYPE(h2)), removeMarkdown(remove_TYPE(h2)),
removeMarkdown(remove_TYPE(h3)) 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()), content: plaintext(lines.join('\n').trim()),
rank rank
}); });

Loading…
Cancel
Save