mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-17 03:01:25 +00:00
docs: set-up sapper template
This commit is contained in:
parent
cd369f147a
commit
04b8978ec2
22 changed files with 5209 additions and 0 deletions
21
docs/src/routes/blog/[slug].json.js
Normal file
21
docs/src/routes/blog/[slug].json.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import posts from "./_posts.js";
|
||||
|
||||
const lookup = new Map();
|
||||
|
||||
posts.forEach((post) => {
|
||||
lookup.set(post.slug, JSON.stringify(post));
|
||||
});
|
||||
|
||||
export function get(req, res, next) {
|
||||
// the `slug` parameter is available because
|
||||
// this file is called [slug].json.js
|
||||
const { slug } = req.params;
|
||||
|
||||
if (lookup.has(slug)) {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(lookup.get(slug));
|
||||
} else {
|
||||
res.writeHead(404, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ message: `Not found` }));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue