Kodama Tutorials [index-en-US]

Backlinks

Kodama 教程 [tutorials]

安装 [install]

你可以根据目标设备的架构直接从 Github Release 页面下载二进制文件. 在 Termux 等 Android 环境中使用请选择 aarch64-unknown-linux-musl 架构.

  • 确保 Kodama 位于可执行目录.
  • 确保 Kodama 有可执行权限.
  • 如果你乐意, 将 Kodama 添加到环境变量.
  • Kodama 不内置 Typst, 因此如果你的内容涉及 Typst 文本, 你需要保证环境变量中有可用的 Typst 程序.

Github Release 页面缺少适合你设备的文件时, 你可以从 源代码 开始自己构建, 这也很容易.

编译 [compile]

指令 kodama compile 或缩写为 kodama c 将根据输入的 Markdown 工作区路径构建出 HTML 文件. 默认位于工作区路径的 publish 文件夹下.
尽管有 --root 参数, 但仍然建议所有用户在 index.md 文件所在的目录下执行 kodama c.

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

举例来说, 如果最终部署到的 URL 为 https://www.example.com/blog, 这并非该域名的根目录, 为了保证生成链接的正确性, 用户应该指定 --base 这一编译参数, 即

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

注意. 当然, 如果用户只是在本地使用, 就不必考虑这个问题了.

本地预览 [publish]

如果你希望在本地查看生成页面 publish/ 的效果, 通常你需要一个本地 http 服务器. 你可以使用任何你熟悉的工具完成这件事. 此处推荐 miniserve, 安装后在 Kodama 项目的根路径执行如下指令即可.

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

持续集成 [github-workflow]

一个可供参考的 Github Workflow 配置 如下 1. 唯一需要注意的是环境变量 $PAGE_URL, 用于 指定待部署页面的 URL, 你可以在仓库的 settings/variables/actions 设置 它们.

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

Hong Jiarong 提供.