@egoist/akira v1.4.0
💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.
AKIRA
Install
npm i -D @egoist/akiraGuide
Commands
# Run dev server
akira [dir]
# Build static site
# Outputs to `out` directory.
akira build [dir]Svelte Pages
Akira uses file-system based routing, which means .svelte files and JavaScript files in pages folder will be automatically generated as static HTML files. For example:
pages/index.sveltecorresponds to/index.htmlpages/about/me.sveltecorresponds to/about/me/index.html
It also supports dynamic paramater in route path. For example:
pages/[slug].sveltecorresponds to/:slug/index.svelte
In pages, you can export a loader function to fetch data before each request, in a page with dynamic paramaters, you can dynamically fetch data based on the parameters:
<!-- pages/[slug].svelte -->
<script context="module">
export const loader = async (ctx) => {
const post = await fetch(
`https://some.api/post/${ctx.params.slug}`,
).then((res) => res.json())
return {
props: {
post,
},
}
}
</script>
<script>
export let post
</script>
<h1>{post.title}</h1>
<div>{@html post.content}</div>JavaScript Pages
Sometimes your page doesn't output HTML, for example you may want a page to output JSON or XML string. Such pages can be authored in JavaScript or TypeScript, let's say you want to generate a XML page for your RSS feed, create a pages/rss.xml.ts:
import { defineHandler } from '@egoist/akira'
export default defineHandler(() => {
return {
body: `...some XML string`,
}
})Then you will get a static file generated to /rss.xml containing ...some XML string.
License
MIT © EGOIST