静的サイトジェネレータを作った
rustで静的サイトジェネレータを作りました。ailogといいます。hugo
からの移行になります。
ailog
は、最初にatproto-comment-system(oauth)とask-AIという機能をつけました。
quick start
$ git clone https://git.syui.ai/ai/log
$ cd log
$ cargo build
$ ./target/debug/ailog init my-blog
$ ./target/debug/ailog serve my-blog
install
$ cargo install --path .
---
$ export CARGO_HOME="$HOME/.cargo"
$ export RUSTUP_HOME="$HOME/.rustup"
$ export PATH="$HOME/.cargo/bin:$PATH"
---
$ which ailog
$ ailog -h
build deploy
$ cd my-blog
$ vim config.toml
$ ailog new test
$ vim content/posts/`date +"%Y-%m-%d"`.md
$ ailog build
# publicの中身をweb-serverにdeploy
$ cp -rf ./public/* ./web-server/root/
atproto-comment-system
example
$ cd ./oauth
$ npm i
$ npm run build
$ npm run preview
# Production environment variables
VITE_APP_HOST=https://example.com
VITE_OAUTH_CLIENT_ID=https://example.com/client-metadata.json
VITE_OAUTH_REDIRECT_URI=https://example.com/oauth/callback
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
# Collection names for OAuth app
VITE_COLLECTION_COMMENT=ai.syui.log
VITE_COLLECTION_USER=ai.syui.log.user
VITE_COLLECTION_CHAT=ai.syui.log.chat
# Collection names for ailog (backward compatibility)
AILOG_COLLECTION_COMMENT=ai.syui.log
AILOG_COLLECTION_USER=ai.syui.log.user
# API Configuration
VITE_BSKY_PUBLIC_API=https://public.api.bsky.app
これはailog oauth build my-blog
で./my-blog/config.toml
から./oauth/.env.production
が生成されます。
$ ailog oauth build my-blog
use
簡単に説明すると、./oauth
で生成するのがatproto-comment-system
です。
<script type="module" crossorigin src="/assets/comment-atproto-${hash}}.js"></script>
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-${hash}.css">
<section class="comment-section"> <div id="comment-atproto"></div> </section>
ただし、oauthであるため、色々と大変です。本番環境(もしくは近い形)でテストを行いましょう。cf, tailscale, ngrokなど。
tunnel: ${hash}
credentials-file: ${path}.json
ingress:
- hostname: example.com
service: http://localhost:4173
originRequest:
noHappyEyeballs: true
- service: http_status:404
# tunnel list, dnsに登録が必要です
$ cloudflared tunnel list
$ cloudflared tunnel --config cloudflared-config.yml run
$ cloudflared tunnel route dns ${uuid} example.com
以下の2つのcollection recordを生成します。ユーザーにはai.syui.log
が生成され、ここにコメントが記録されます。それを取得して表示しています。ai.syui.log.user
は管理者であるVITE_ADMIN_DID
用です。
VITE_COLLECTION_COMMENT=ai.syui.log
VITE_COLLECTION_USER=ai.syui.log.user
$ ailog auth login
$ ailog stream server
このコマンドでai.syui.log
をjetstream
から監視して、書き込みがあれば、管理者のai.syui.log.user
に記録され、そのuser-listに基づいて、コメント一覧を取得します。
つまり、コメント表示のアカウントを手動で設定するか、自動化するか。自動化するならserverでailog stream server
を動かさなければいけません。
ask-AI
ask-AI
の仕組みは割愛します。後に変更される可能性が高いと思います。
local llm, mcp, atprotoと組み合わせです。
code syntax
# comment
d=${0:a:h}
// This is a comment
fn main() {
println!("Hello, world!");
}
// This is a comment
console.log("Hello, world!");