sveltejs / site-kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

First link on "On this page" for Docs doesn't provides and href for the anchor.

SrGeneroso opened this issue · comments

In the SvelteKit docs you can't navigate to the top of the document as the first/root object of the sidebar doesn't apply the href
brave_yvkkYYeasY

This seems to only apply to the SvelteKit Docs as it has a different implementation from the Svelte docs although they both use the component

I'm not sure how to build the project myself and for sure if I PR it would be a hacky thing so I'll be around to provide any help but I would rather prefer to somebody with more knowledge to tackle this one.

I've found that there is a couple of properties missing in the library for retrieving data for the pages on the docs.
Apparently, some work was done to get this properties but then is discarded. I've include those properties again and seems to be working, however, I export both properties with the same value as it doesn't look like I need the "path" formatting that is done in the svelte docs

Please note that there is still a TODO
// TODO this should probably use a type from site-kit because apparently we extend the original component type with a new category property, nonetheless, now it satisfies the type and should work.
This could be my first PR to open source. Any tips?

export const categories = {};
export const pages = {};

for (const [file, asset] of Object.entries(meta)) {
	const slug = /\/\d{2}-(.+)\/meta\.json$/.exec(file)[1];

	const { title, draft } = await read(asset).json();

	if (draft) continue;

	categories[slug] = {
		title,
		pages: []
	};
}

for (const [file, asset] of Object.entries(markdown)) {
	const [, category_dir, basename] = /\/(\d{2}-.+?)\/(\d{2}-.+\.md)$/.exec(file);
	const category_slug = category_dir.slice(3);
	const slug = basename.slice(3, -3); // strip the number prefix and .md suffix

	const category = categories[category_slug];
	if (!category) continue; // draft

	const {
		metadata: { draft, title, rank },
		body
	} = extractFrontmatter(await read(asset).text());

	if (draft === 'true') continue;

	category.pages.push({
		title,
		path: `${base}/docs/${slug}`
	});

	pages[slug] = {
		rank: +rank || undefined,
		category: category.title,
		title,
		file: `${category_dir}/${basename}`,
		slug,
		path: slug,
		sections: await get_sections(body),
		body
	};
}

/** @param {string} slug */
export async function get_parsed_docs(slug) {
	const page = pages[slug];
	if (!page) error(404);

	// TODO this should probably use a type from site-kit
	return {
		category: page.category,
		title: page.title,
		file: page.file,
		path: page.path,
		slug: page.slug,
		sections: page.sections,
		content: await render_content(page.file, page.body)
	};
}
 

Since this is a problem with the kit repo I'll reopen the issue and solve it there.