158 lines
3.8 KiB
Markdown
158 lines
3.8 KiB
Markdown
---
|
|
title: "静的サイトジェネレータを作った"
|
|
slug: "ailog"
|
|
date: "2025-06-12"
|
|
tags: ["blog", "rust", "mcp", "atp"]
|
|
language: ["ja", "en"]
|
|
---
|
|
|
|
rustで静的サイトジェネレータを作りました。[ailog](https://git.syui.ai/ai/log)といいます。`hugo`からの移行になります。
|
|
|
|
`ailog`は、最初にatproto-comment-system(oauth)とask-AIという機能をつけました。
|
|
|
|
## quick start
|
|
|
|
```sh
|
|
$ 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
|
|
|
|
```sh
|
|
$ 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
|
|
|
|
```sh
|
|
$ 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
|
|
|
|
```sh
|
|
$ cd ./oauth
|
|
$ npm i
|
|
$ npm run build
|
|
$ npm run preview
|
|
```
|
|
|
|
```sh:ouath/.env.production
|
|
# Production environment variables
|
|
VITE_APP_HOST=https://syui.ai
|
|
VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
|
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
|
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
|
|
|
# Base collection (all others are derived via getCollectionNames)
|
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
|
|
|
# AI Configuration
|
|
VITE_AI_ENABLED=true
|
|
VITE_AI_ASK_AI=true
|
|
VITE_AI_PROVIDER=ollama
|
|
VITE_AI_MODEL=gemma3:4b
|
|
VITE_AI_HOST=https://ollama.syui.ai
|
|
VITE_AI_SYSTEM_PROMPT="ai"
|
|
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
|
|
|
# API Configuration
|
|
VITE_BSKY_PUBLIC_API=https://public.api.bsky.app
|
|
VITE_ATPROTO_API=https://bsky.social
|
|
```
|
|
|
|
これは`ailog oauth build my-blog`で`./my-blog/config.toml`から`./oauth/.env.production`が生成されます。
|
|
|
|
```sh
|
|
$ ailog oauth build my-blog
|
|
```
|
|
|
|
### use
|
|
|
|
簡単に説明すると、`./oauth`で生成するのが`atproto-comment-system`です。
|
|
|
|
```html
|
|
<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など。
|
|
|
|
```yml:cloudflared-config.yml
|
|
tunnel: ${hash}
|
|
credentials-file: ${path}.json
|
|
|
|
ingress:
|
|
- hostname: example.com
|
|
service: http://localhost:4173
|
|
originRequest:
|
|
noHappyEyeballs: true
|
|
|
|
- service: http_status:404
|
|
```
|
|
|
|
```sh
|
|
# tunnel list, dnsに登録が必要です
|
|
$ cloudflared tunnel list
|
|
$ cloudflared tunnel --config cloudflared-config.yml run
|
|
$ cloudflared tunnel route dns ${uuid} example.com
|
|
```
|
|
|
|
```sh
|
|
$ ailog auth init
|
|
$ ailog stream server
|
|
```
|
|
|
|
このコマンドで`ai.syui.log`を`jetstream`から監視して、書き込みがあれば、管理者の`ai.syui.log.user`に記録され、そのuser-listに基づいて、コメント一覧を取得します。
|
|
|
|
つまり、コメント表示のアカウントを手動で設定するか、自動化するか。自動化するならserverで`ailog stream server`を動かさなければいけません。
|
|
|
|
## ask-AI
|
|
|
|
`ask-AI`の仕組みは割愛します。後に変更される可能性が高いと思います。
|
|
|
|
`llm`, `mcp`, `atproto`などの組み合わせです。
|
|
|
|
現在、`/index.json`を監視して、更新があれば、翻訳などを行い自動ポストする機能があります。
|
|
|
|
## code syntax
|
|
|
|
```zsh:/path/to/test.zsh
|
|
# comment
|
|
d=${0:a:h}
|
|
```
|
|
|
|
```rust:/path/to/test.rs
|
|
// This is a comment
|
|
fn main() {
|
|
println!("Hello, world!");
|
|
}
|
|
```
|
|
|
|
```js:/path/to/test.js
|
|
// This is a comment
|
|
console.log("Hello, world!");
|
|
```
|
|
|