1.4.0 • Published 3 years ago

@egoist/akira v1.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


AKIRA

npm version

Install

npm i -D @egoist/akira

Guide

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.svelte corresponds to /index.html
  • pages/about/me.svelte corresponds to /about/me/index.html

It also supports dynamic paramater in route path. For example:

  • pages/[slug].svelte corresponds 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

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago