Giter VIP home page Giter VIP logo

Comments (2)

SrGeneroso avatar SrGeneroso commented on July 21, 2024

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)
	};
}
 

from site-kit.

SrGeneroso avatar SrGeneroso commented on July 21, 2024

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

from site-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.