Kodama 教程 [tutorials]

Backlinks

Kodama Tutorials [index-en-US]

Installation [install-en-US]

You can directly download the binary file from the Github Release page based on the architecture of your target device. For use in Android environments like Termux, choose the aarch64-unknown-linux-musl architecture.

  • Ensure that Kodama is located in an executable directory.
  • Make sure Kodama has executable permissions.
  • If you wish, add Kodama to your environment variables.
  • Kodama does not come with Typst built-in, so if your content involves Typst text, you need to ensure that a Typst program is available in your environment variables.

When the Github Release page does not have a file suitable for your device, you can start by building from source code yourself, which is also quite easy.

Compilation [compile-en-US]

The command kodama compile or its abbreviation kodama c will build HTML files based on the input Markdown workspace path. By default, these files are placed in the publish folder within the workspace path. Even with the --root parameter, it is still recommended for all users to execute kodama c in the directory where the index.md file is located.

shell [compile-help]

$ kodama c --help
Compile current workspace dir to HTMLs

Usage: kodama.exe compile [OPTIONS]

OOptions:
  -b, --base <BASE>                Base URL or publish URL (e.g. https://www.example.com/) [default: /] 
  -o, --output <OUTPUT>            Path to output dir [default: ./publish]
  -r, --root <ROOT>                Configures the project root (for absolute paths) [default: ./]       
  -d, --disable-pretty-urls        Disable pretty urls (`/page` to `/page.html`)
  -s, --short-slug                 Hide parents part in slug (e.g. `tutorials/install` to `install`)    
  -f, --footer-mode <FOOTER_MODE>  Specify the inline mode for the footer sections [default: link] [possible values: link, embed]
  -h, --help                       Print help

For example, if the final deployment URL is https://www.example.com/blog, which is not the root directory of the domain, to ensure the correctness of the generated links, the user should specify the --base compilation parameter, like so:

kodama c -b=https://www.example.com/blog

Note that this is only necessary if you are deploying to a specific subdirectory. If you are using it locally, you don’t need to consider this issue.

Preview [publish-en-US]

If you want to view the generated pages in the publish/ directory locally, you typically need a local HTTP server. You can use any tool you are familiar with to accomplish this. Here, miniserve is recommended. After installing it, you can run the following command in the root path of your Kodama project to serve the pages locally.

miniserve ./publish --index index.html --pretty-urls

Github CI [github-workflow-en-US]

A reference GitHub Workflow configuration can be found here 1. The only thing to note is the environment variable $PAGE_URL, which is used to specify the URL of the page to be deployed. You can set these in the settings/variables/actions section of your repository.

workflow.yml [workflow-yml]

name: Deploy Kodama site to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

# Default to bash
defaults:
  run:
    shell: bash

jobs:
  # Build job
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Install Kodama & Typst
        run: |
          cargo install --git https://github.com/kokic/kodama.git
          sudo snap install typst
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Setup Pages
        id: pages
        uses: actions/configure-pages@v5
      - name: Build with Kodama
        run: |
          kodama c -b $PAGE_URL
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: ./publish

# Deployment job
  deploy:
    environment:
      name: github-pages
      url: $PAGE_URL
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

1

Provided by Hong Jiarong.