Compare commits
72 Commits
b2fa06d5fa
...
v0.2.2
Author | SHA1 | Date | |
---|---|---|---|
b17ac3d91a
|
|||
81f87d0462
|
|||
a020fa24d8
|
|||
21c53010b7
|
|||
4f7834f85c
|
|||
fecd927b91
|
|||
b54e8089ea
|
|||
174cb12d4d
|
|||
a1186f8185
|
|||
833549756b
|
|||
4edde5293a
|
|||
f0fdf678c8
|
|||
820e47f634
|
|||
4dac4a83e0
|
|||
fccf75949c
|
|||
6600a9e0cf
|
|||
0d79af5aa5
|
|||
db04af76ab
|
|||
5f0b09b555
|
|||
8fa9e474d1
|
|||
5339dd28b0
|
|||
1e83b50e3f
|
|||
889ce8baa1
|
|||
286b46c6e6
|
|||
b780d27ace
|
|||
831fcb7865
|
|||
3f8bbff7c2
|
|||
5cb73a9ed3
|
|||
6ce8d44c4b
|
|||
167cfb35f7
|
|||
c8377ceabf
|
|||
e917c563f2
|
|||
a76933c23b
|
|||
8d960b7a40
|
|||
d3967c782f
|
|||
63b6fd5142
|
|||
27935324c7
|
|||
594d7e7aef
|
|||
be86c11e74
|
|||
619675b551
|
|||
d4d98e2e91
|
|||
8dac463345
|
|||
095f6ec386
|
|||
c12d42882c
|
|||
67b241f1e8
|
|||
4206b2195d
|
|||
b3c1b01e9e
|
|||
ffa4fa0846
|
|||
0e75d4c0e6
|
|||
b7f62e729a
|
|||
3b2c53fc97
|
|||
13f1785081
|
|||
bb6d51a602
|
|||
a4114c5be3
|
|||
5c13dc0a1c
|
|||
cef0675a88
|
|||
fd223290df
|
|||
5f4382911b
|
|||
95cee69482
|
|||
33c166fa0c
|
|||
36863e4d9f
|
|||
fb0e5107cf
|
|||
962017f922
|
|||
5ce03098bd
|
|||
acce1d5af3
|
|||
bf0b72a52d
|
|||
6e6c6e2f53
|
|||
eb5aa0a2be
|
|||
ad45b151b1
|
|||
4775fa7034
|
|||
d396dbd052
|
|||
ec3e3d1f89
|
@@ -33,7 +33,27 @@
|
|||||||
"Bash(./scripts/test-oauth.sh:*)",
|
"Bash(./scripts/test-oauth.sh:*)",
|
||||||
"Bash(./run.zsh:*)",
|
"Bash(./run.zsh:*)",
|
||||||
"Bash(npm run dev:*)",
|
"Bash(npm run dev:*)",
|
||||||
"Bash(./target/release/ailog:*)"
|
"Bash(./target/release/ailog:*)",
|
||||||
|
"Bash(rg:*)",
|
||||||
|
"Bash(../target/release/ailog build)",
|
||||||
|
"Bash(zsh run.zsh:*)",
|
||||||
|
"Bash(hugo:*)",
|
||||||
|
"WebFetch(domain:docs.bsky.app)",
|
||||||
|
"WebFetch(domain:syui.ai)",
|
||||||
|
"Bash(rustup target list:*)",
|
||||||
|
"Bash(rustup target:*)",
|
||||||
|
"Bash(git add:*)",
|
||||||
|
"Bash(git commit:*)",
|
||||||
|
"Bash(git push:*)",
|
||||||
|
"Bash(git tag:*)",
|
||||||
|
"Bash(../bin/ailog:*)",
|
||||||
|
"Bash(../target/release/ailog oauth build:*)",
|
||||||
|
"Bash(ailog:*)",
|
||||||
|
"WebFetch(domain:plc.directory)",
|
||||||
|
"WebFetch(domain:atproto.com)",
|
||||||
|
"WebFetch(domain:syu.is)",
|
||||||
|
"Bash(sed:*)",
|
||||||
|
"Bash(./scpt/run.zsh:*)"
|
||||||
],
|
],
|
||||||
"deny": []
|
"deny": []
|
||||||
}
|
}
|
||||||
|
53
.gitea/workflows/deploy.yml
Normal file
53
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: Deploy to Cloudflare Pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Build ailog
|
||||||
|
run: |
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
- name: Build OAuth app
|
||||||
|
run: |
|
||||||
|
cd oauth
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
- name: Copy OAuth assets
|
||||||
|
run: |
|
||||||
|
cp -r oauth/dist/* my-blog/static/
|
||||||
|
|
||||||
|
- name: Generate site with ailog
|
||||||
|
run: |
|
||||||
|
./target/release/ailog generate --input content --output my-blog/public
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
projectName: syui-ai
|
||||||
|
directory: my-blog/public
|
||||||
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
28
.gitea/workflows/example-usage.yml
Normal file
28
.gitea/workflows/example-usage.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: Example ailog usage
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch: # Manual trigger for testing
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-with-ailog-action:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build with ailog action
|
||||||
|
uses: ai/log@v1 # This will reference this repository
|
||||||
|
with:
|
||||||
|
content-dir: 'content'
|
||||||
|
output-dir: 'public'
|
||||||
|
ai-integration: true
|
||||||
|
atproto-integration: true
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
projectName: my-blog
|
||||||
|
directory: public
|
157
.github/workflows/cloudflare-pages.yml
vendored
Normal file
157
.github/workflows/cloudflare-pages.yml
vendored
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
name: Deploy to Cloudflare Pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
OAUTH_DIR: oauth_new
|
||||||
|
KEEP_DEPLOYMENTS: 5
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '21'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
cd ${{ env.OAUTH_DIR }}
|
||||||
|
npm install
|
||||||
|
|
||||||
|
- name: Build OAuth app
|
||||||
|
run: |
|
||||||
|
cd ${{ env.OAUTH_DIR }}
|
||||||
|
NODE_ENV=production npm run build
|
||||||
|
- name: Copy OAuth build to static
|
||||||
|
run: |
|
||||||
|
rm -rf my-blog/static/assets
|
||||||
|
cp -rf ${{ env.OAUTH_DIR }}/dist/* my-blog/static/
|
||||||
|
cp ${{ env.OAUTH_DIR }}/dist/index.html my-blog/templates/oauth-assets.html
|
||||||
|
|
||||||
|
- name: Cache ailog binary
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ./bin
|
||||||
|
key: ailog-bin-${{ runner.os }}
|
||||||
|
restore-keys: |
|
||||||
|
ailog-bin-${{ runner.os }}
|
||||||
|
|
||||||
|
- name: Setup ailog binary
|
||||||
|
run: |
|
||||||
|
# Get expected version from Cargo.toml
|
||||||
|
EXPECTED_VERSION=$(grep '^version' Cargo.toml | cut -d'"' -f2)
|
||||||
|
echo "Expected version from Cargo.toml: $EXPECTED_VERSION"
|
||||||
|
|
||||||
|
# Check current binary version if exists
|
||||||
|
if [ -f "./bin/ailog" ]; then
|
||||||
|
CURRENT_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||||
|
echo "Current binary version: $CURRENT_VERSION"
|
||||||
|
else
|
||||||
|
CURRENT_VERSION="none"
|
||||||
|
echo "No binary found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check OS
|
||||||
|
OS="${{ runner.os }}"
|
||||||
|
echo "Runner OS: $OS"
|
||||||
|
|
||||||
|
# Use pre-packaged binary if version matches or extract from tar.gz
|
||||||
|
if [ "$CURRENT_VERSION" = "$EXPECTED_VERSION" ]; then
|
||||||
|
echo "Binary is up to date"
|
||||||
|
chmod +x ./bin/ailog
|
||||||
|
elif [ "$OS" = "Linux" ] && [ -f "./bin/ailog-linux-x86_64.tar.gz" ]; then
|
||||||
|
echo "Extracting ailog from pre-packaged tar.gz..."
|
||||||
|
cd bin
|
||||||
|
tar -xzf ailog-linux-x86_64.tar.gz
|
||||||
|
chmod +x ailog
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Verify extracted version
|
||||||
|
EXTRACTED_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||||
|
echo "Extracted binary version: $EXTRACTED_VERSION"
|
||||||
|
|
||||||
|
if [ "$EXTRACTED_VERSION" != "$EXPECTED_VERSION" ]; then
|
||||||
|
echo "Warning: Binary version mismatch. Expected $EXPECTED_VERSION but got $EXTRACTED_VERSION"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: No suitable binary found for OS: $OS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build site with ailog
|
||||||
|
run: |
|
||||||
|
cd my-blog
|
||||||
|
../bin/ailog build
|
||||||
|
|
||||||
|
- name: List public directory
|
||||||
|
run: |
|
||||||
|
ls -la my-blog/public/
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
|
||||||
|
directory: my-blog/public
|
||||||
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
wranglerVersion: '3'
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
needs: deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: success()
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Wait for deployment to complete
|
||||||
|
run: sleep 3
|
||||||
|
|
||||||
|
- name: Cleanup old deployments
|
||||||
|
run: |
|
||||||
|
# Get all deployments
|
||||||
|
DEPLOYMENTS=$(curl -s -X GET \
|
||||||
|
"https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${{ secrets.CLOUDFLARE_PROJECT_NAME }}/deployments" \
|
||||||
|
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/json")
|
||||||
|
|
||||||
|
# Extract deployment IDs (skip the latest N deployments)
|
||||||
|
DEPLOYMENT_IDS=$(echo "$DEPLOYMENTS" | jq -r ".result | sort_by(.created_on) | reverse | .[${{ env.KEEP_DEPLOYMENTS }}:] | .[].id // empty")
|
||||||
|
|
||||||
|
if [ -z "$DEPLOYMENT_IDS" ]; then
|
||||||
|
echo "No old deployments to delete"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Delete old deployments
|
||||||
|
for ID in $DEPLOYMENT_IDS; do
|
||||||
|
echo "Deleting deployment: $ID"
|
||||||
|
RESPONSE=$(curl -s -X DELETE \
|
||||||
|
"https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${{ secrets.CLOUDFLARE_PROJECT_NAME }}/deployments/$ID" \
|
||||||
|
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/json")
|
||||||
|
|
||||||
|
SUCCESS=$(echo "$RESPONSE" | jq -r '.success')
|
||||||
|
if [ "$SUCCESS" = "true" ]; then
|
||||||
|
echo "Successfully deleted deployment: $ID"
|
||||||
|
else
|
||||||
|
echo "Failed to delete deployment: $ID"
|
||||||
|
echo "$RESPONSE" | jq .
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1 # Rate limiting
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Cleanup completed!"
|
62
.github/workflows/deploy.yml
vendored
62
.github/workflows/deploy.yml
vendored
@@ -1,62 +0,0 @@
|
|||||||
name: Deploy ailog
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Cache cargo registry
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: ~/.cargo/registry
|
|
||||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Cache cargo index
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: ~/.cargo/git
|
|
||||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Cache cargo build
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: target
|
|
||||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Build ailog
|
|
||||||
run: cargo build --release
|
|
||||||
|
|
||||||
- name: Generate static site
|
|
||||||
run: |
|
|
||||||
./target/release/ailog build my-blog
|
|
||||||
touch my-blog/public/.nojekyll
|
|
||||||
|
|
||||||
- name: Setup Cloudflare Pages
|
|
||||||
run: |
|
|
||||||
# Cloudflare Pages用の設定
|
|
||||||
echo '/* /index.html 200' > my-blog/public/_redirects
|
|
||||||
echo 'X-Frame-Options: DENY' > my-blog/public/_headers
|
|
||||||
echo 'X-Content-Type-Options: nosniff' >> my-blog/public/_headers
|
|
||||||
|
|
||||||
- name: Deploy to GitHub Pages
|
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
publish_dir: ./my-blog/public
|
|
||||||
publish_branch: gh-pages
|
|
92
.github/workflows/disabled/gh-pages-fast.yml
vendored
Normal file
92
.github/workflows/disabled/gh-pages-fast.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
name: github pages (fast)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths-ignore:
|
||||||
|
- 'src/**'
|
||||||
|
- 'Cargo.toml'
|
||||||
|
- 'Cargo.lock'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Cache ailog binary
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ./bin
|
||||||
|
key: ailog-bin-${{ runner.os }}
|
||||||
|
restore-keys: |
|
||||||
|
ailog-bin-${{ runner.os }}
|
||||||
|
|
||||||
|
- name: Setup ailog binary
|
||||||
|
run: |
|
||||||
|
# Get expected version from Cargo.toml
|
||||||
|
EXPECTED_VERSION=$(grep '^version' Cargo.toml | cut -d'"' -f2)
|
||||||
|
echo "Expected version from Cargo.toml: $EXPECTED_VERSION"
|
||||||
|
|
||||||
|
# Check current binary version if exists
|
||||||
|
if [ -f "./bin/ailog" ]; then
|
||||||
|
CURRENT_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||||
|
echo "Current binary version: $CURRENT_VERSION"
|
||||||
|
else
|
||||||
|
CURRENT_VERSION="none"
|
||||||
|
echo "No binary found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check OS
|
||||||
|
OS="${{ runner.os }}"
|
||||||
|
echo "Runner OS: $OS"
|
||||||
|
|
||||||
|
# Use pre-packaged binary if version matches or extract from tar.gz
|
||||||
|
if [ "$CURRENT_VERSION" = "$EXPECTED_VERSION" ]; then
|
||||||
|
echo "Binary is up to date"
|
||||||
|
chmod +x ./bin/ailog
|
||||||
|
elif [ "$OS" = "Linux" ] && [ -f "./bin/ailog-linux-x86_64.tar.gz" ]; then
|
||||||
|
echo "Extracting ailog from pre-packaged tar.gz..."
|
||||||
|
cd bin
|
||||||
|
tar -xzf ailog-linux-x86_64.tar.gz
|
||||||
|
chmod +x ailog
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Verify extracted version
|
||||||
|
EXTRACTED_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||||
|
echo "Extracted binary version: $EXTRACTED_VERSION"
|
||||||
|
|
||||||
|
if [ "$EXTRACTED_VERSION" != "$EXPECTED_VERSION" ]; then
|
||||||
|
echo "Warning: Binary version mismatch. Expected $EXPECTED_VERSION but got $EXTRACTED_VERSION"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: No suitable binary found for OS: $OS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Setup Hugo
|
||||||
|
uses: peaceiris/actions-hugo@v3
|
||||||
|
with:
|
||||||
|
hugo-version: "0.139.2"
|
||||||
|
extended: true
|
||||||
|
|
||||||
|
- name: Build with ailog
|
||||||
|
env:
|
||||||
|
TZ: "Asia/Tokyo"
|
||||||
|
run: |
|
||||||
|
# Use pre-built ailog binary instead of cargo build
|
||||||
|
cd my-blog
|
||||||
|
../bin/ailog build
|
||||||
|
touch ./public/.nojekyll
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./my-blog/public
|
||||||
|
publish_branch: gh-pages
|
169
.github/workflows/release.yml
vendored
Normal file
169
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Release tag (e.g., v1.0.0)'
|
||||||
|
required: true
|
||||||
|
default: 'v0.1.0'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
actions: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
OPENSSL_STATIC: true
|
||||||
|
OPENSSL_VENDOR: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build ${{ matrix.target }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- target: x86_64-unknown-linux-gnu
|
||||||
|
os: ubuntu-latest
|
||||||
|
artifact_name: ailog
|
||||||
|
asset_name: ailog-linux-x86_64
|
||||||
|
- target: aarch64-unknown-linux-gnu
|
||||||
|
os: ubuntu-latest
|
||||||
|
artifact_name: ailog
|
||||||
|
asset_name: ailog-linux-aarch64
|
||||||
|
- target: x86_64-apple-darwin
|
||||||
|
os: macos-latest
|
||||||
|
artifact_name: ailog
|
||||||
|
asset_name: ailog-macos-x86_64
|
||||||
|
- target: aarch64-apple-darwin
|
||||||
|
os: macos-latest
|
||||||
|
artifact_name: ailog
|
||||||
|
asset_name: ailog-macos-aarch64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
targets: ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Install cross-compilation tools (Linux)
|
||||||
|
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
|
||||||
|
|
||||||
|
- name: Configure cross-compilation (Linux ARM64)
|
||||||
|
if: matrix.target == 'aarch64-unknown-linux-gnu'
|
||||||
|
run: |
|
||||||
|
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml
|
||||||
|
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
|
||||||
|
|
||||||
|
- name: Cache cargo registry
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- name: Cache target directory
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: target
|
||||||
|
key: ${{ runner.os }}-${{ matrix.target }}-target-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release --target ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Prepare binary
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cd target/${{ matrix.target }}/release
|
||||||
|
|
||||||
|
# Use appropriate strip command for cross-compilation
|
||||||
|
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
|
||||||
|
aarch64-linux-gnu-strip ${{ matrix.artifact_name }} || echo "Strip failed, continuing..."
|
||||||
|
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
|
||||||
|
strip ${{ matrix.artifact_name }} || echo "Strip failed, continuing..."
|
||||||
|
else
|
||||||
|
strip ${{ matrix.artifact_name }} || echo "Strip failed, continuing..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create archive
|
||||||
|
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
|
||||||
|
7z a ../../../${{ matrix.asset_name }}.zip ${{ matrix.artifact_name }}
|
||||||
|
else
|
||||||
|
tar czvf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload binary
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.asset_name }}
|
||||||
|
path: ${{ matrix.asset_name }}.tar.gz
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Create Release
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
actions: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Generate release notes
|
||||||
|
run: |
|
||||||
|
echo "## What's Changed" > release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "### Features" >> release_notes.md
|
||||||
|
echo "- AI-powered static blog generator" >> release_notes.md
|
||||||
|
echo "- AtProto OAuth integration" >> release_notes.md
|
||||||
|
echo "- Automatic translation support" >> release_notes.md
|
||||||
|
echo "- AI comment system" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "### Platforms" >> release_notes.md
|
||||||
|
echo "- Linux (x86_64, aarch64)" >> release_notes.md
|
||||||
|
echo "- macOS (Intel, Apple Silicon)" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "### Installation" >> release_notes.md
|
||||||
|
echo "\`\`\`bash" >> release_notes.md
|
||||||
|
echo "# Linux/macOS" >> release_notes.md
|
||||||
|
echo "tar -xzf ailog-linux-x86_64.tar.gz" >> release_notes.md
|
||||||
|
echo "chmod +x ailog" >> release_notes.md
|
||||||
|
echo "sudo mv ailog /usr/local/bin/" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "\`\`\`" >> release_notes.md
|
||||||
|
|
||||||
|
- name: Get tag name
|
||||||
|
id: tag_name
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||||
|
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
tag_name: ${{ steps.tag_name.outputs.tag }}
|
||||||
|
name: ailog ${{ steps.tag_name.outputs.tag }}
|
||||||
|
body_path: release_notes.md
|
||||||
|
draft: false
|
||||||
|
prerelease: ${{ contains(steps.tag_name.outputs.tag, 'alpha') || contains(steps.tag_name.outputs.tag, 'beta') || contains(steps.tag_name.outputs.tag, 'rc') }}
|
||||||
|
files: artifacts/*/ailog-*.tar.gz
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
14
.gitignore
vendored
14
.gitignore
vendored
@@ -5,8 +5,16 @@
|
|||||||
*.swo
|
*.swo
|
||||||
*~
|
*~
|
||||||
.DS_Store
|
.DS_Store
|
||||||
cloudflare*
|
my-blog/public/
|
||||||
my-blog
|
|
||||||
dist
|
dist
|
||||||
package-lock.json
|
|
||||||
node_modules
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
my-blog/static/assets/comment-atproto-*
|
||||||
|
bin/ailog
|
||||||
|
docs
|
||||||
|
my-blog/static/index.html
|
||||||
|
my-blog/templates/oauth-assets.html
|
||||||
|
cloudflared-config.yml
|
||||||
|
.config
|
||||||
|
oauth-server-example
|
||||||
|
atproto
|
||||||
|
45
Cargo.toml
45
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ailog"
|
name = "ailog"
|
||||||
version = "0.1.0"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["syui"]
|
authors = ["syui"]
|
||||||
description = "A static blog generator with AI features"
|
description = "A static blog generator with AI features"
|
||||||
@@ -10,12 +10,16 @@ license = "MIT"
|
|||||||
name = "ailog"
|
name = "ailog"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "ailog"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
pulldown-cmark = "0.11"
|
pulldown-cmark = "0.11"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tokio = { version = "1.40", features = ["full"] }
|
tokio = { version = "1.40", features = ["rt-multi-thread", "macros", "fs", "net", "io-util", "sync", "time", "process", "signal"] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
@@ -26,7 +30,7 @@ fs_extra = "1.3"
|
|||||||
colored = "2.1"
|
colored = "2.1"
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
syntect = "5.2"
|
syntect = "5.2"
|
||||||
reqwest = { version = "0.12", features = ["json"] }
|
reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
@@ -43,12 +47,39 @@ cookie = "0.18"
|
|||||||
syn = { version = "2.0", features = ["full", "parsing", "visit"] }
|
syn = { version = "2.0", features = ["full", "parsing", "visit"] }
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
ignore = "0.4"
|
ignore = "0.4"
|
||||||
git2 = "0.18"
|
git2 = { version = "0.18", features = ["vendored-openssl", "vendored-libgit2", "ssh"], default-features = false }
|
||||||
regex = "1.0"
|
regex = "1.0"
|
||||||
# ATProto and stream monitoring dependencies
|
# ATProto and stream monitoring dependencies
|
||||||
tokio-tungstenite = { version = "0.21", features = ["native-tls"] }
|
tokio-tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots", "connect"], default-features = false }
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
tungstenite = { version = "0.21", features = ["native-tls"] }
|
tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots"], default-features = false }
|
||||||
|
rpassword = "7.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.14"
|
tempfile = "3.14"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Speed up development builds
|
||||||
|
opt-level = 0
|
||||||
|
debug = true
|
||||||
|
debug-assertions = true
|
||||||
|
overflow-checks = true
|
||||||
|
lto = false
|
||||||
|
panic = 'unwind'
|
||||||
|
incremental = true
|
||||||
|
codegen-units = 256
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
# Optimize release builds for speed and size
|
||||||
|
opt-level = 3
|
||||||
|
debug = false
|
||||||
|
debug-assertions = false
|
||||||
|
overflow-checks = false
|
||||||
|
lto = true
|
||||||
|
panic = 'abort'
|
||||||
|
incremental = false
|
||||||
|
codegen-units = 1
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
# Optimize dependencies in dev builds
|
||||||
|
opt-level = 3
|
150
DEPLOYMENT.md
150
DEPLOYMENT.md
@@ -1,150 +0,0 @@
|
|||||||
# ai.log Deployment Guide
|
|
||||||
|
|
||||||
## 🌐 Cloudflare Tunnel Setup
|
|
||||||
|
|
||||||
ATProto OAuth requires HTTPS for proper CORS handling. Use Cloudflare Tunnel for secure deployment.
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
|
|
||||||
1. **Install cloudflared**:
|
|
||||||
```bash
|
|
||||||
brew install cloudflared
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **Login and create tunnel** (if not already done):
|
|
||||||
```bash
|
|
||||||
cloudflared tunnel login
|
|
||||||
cloudflared tunnel create ailog
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Configure DNS**:
|
|
||||||
- Add a CNAME record: `log.syui.ai` → `[tunnel-id].cfargotunnel.com`
|
|
||||||
|
|
||||||
### Configuration Files
|
|
||||||
|
|
||||||
#### `cloudflared-config.yml`
|
|
||||||
```yaml
|
|
||||||
tunnel: a6813327-f880-485d-a9d1-376e6e3df8ad
|
|
||||||
credentials-file: /Users/syui/.cloudflared/a6813327-f880-485d-a9d1-376e6e3df8ad.json
|
|
||||||
|
|
||||||
ingress:
|
|
||||||
- hostname: log.syui.ai
|
|
||||||
service: http://localhost:8080
|
|
||||||
originRequest:
|
|
||||||
noHappyEyeballs: true
|
|
||||||
- service: http_status:404
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Production Client Metadata
|
|
||||||
`static/client-metadata-prod.json`:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"client_id": "https://log.syui.ai/client-metadata.json",
|
|
||||||
"client_name": "ai.log Blog Comment System",
|
|
||||||
"client_uri": "https://log.syui.ai",
|
|
||||||
"redirect_uris": ["https://log.syui.ai/"],
|
|
||||||
"grant_types": ["authorization_code"],
|
|
||||||
"response_types": ["code"],
|
|
||||||
"token_endpoint_auth_method": "none",
|
|
||||||
"application_type": "web"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Deployment Commands
|
|
||||||
|
|
||||||
#### Quick Start
|
|
||||||
```bash
|
|
||||||
# All-in-one deployment
|
|
||||||
./scripts/tunnel.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Manual Steps
|
|
||||||
```bash
|
|
||||||
# 1. Build for production
|
|
||||||
PRODUCTION=true cargo run -- build
|
|
||||||
|
|
||||||
# 2. Start local server
|
|
||||||
cargo run -- serve --port 8080 &
|
|
||||||
|
|
||||||
# 3. Start tunnel
|
|
||||||
cloudflared tunnel --config cloudflared-config.yml run
|
|
||||||
```
|
|
||||||
|
|
||||||
### Environment Detection
|
|
||||||
|
|
||||||
The system automatically detects environment:
|
|
||||||
|
|
||||||
- **Development** (`localhost:8080`): Uses local client-metadata.json
|
|
||||||
- **Production** (`log.syui.ai`): Uses HTTPS client-metadata.json
|
|
||||||
|
|
||||||
### CORS Resolution
|
|
||||||
|
|
||||||
✅ **With Cloudflare Tunnel**:
|
|
||||||
- HTTPS domain: `https://log.syui.ai`
|
|
||||||
- Valid SSL certificate
|
|
||||||
- Proper CORS headers
|
|
||||||
- ATProto OAuth works correctly
|
|
||||||
|
|
||||||
❌ **With localhost**:
|
|
||||||
- HTTP only: `http://localhost:8080`
|
|
||||||
- CORS restrictions
|
|
||||||
- ATProto OAuth may fail
|
|
||||||
|
|
||||||
### Troubleshooting
|
|
||||||
|
|
||||||
#### ATProto OAuth Errors
|
|
||||||
```javascript
|
|
||||||
// Check client metadata URL in browser console
|
|
||||||
console.log('Environment:', window.location.hostname);
|
|
||||||
console.log('Client ID:', clientId);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Tunnel Connection Issues
|
|
||||||
```bash
|
|
||||||
# Check tunnel status
|
|
||||||
cloudflared tunnel info ailog
|
|
||||||
|
|
||||||
# Test local server
|
|
||||||
curl http://localhost:8080/client-metadata.json
|
|
||||||
```
|
|
||||||
|
|
||||||
#### DNS Propagation
|
|
||||||
```bash
|
|
||||||
# Check DNS resolution
|
|
||||||
dig log.syui.ai
|
|
||||||
nslookup log.syui.ai
|
|
||||||
```
|
|
||||||
|
|
||||||
### Security Notes
|
|
||||||
|
|
||||||
- **Client metadata** is publicly accessible (required by ATProto)
|
|
||||||
- **Credentials file** contains tunnel secrets (keep secure)
|
|
||||||
- **HTTPS only** for production OAuth
|
|
||||||
- **Domain validation** by ATProto servers
|
|
||||||
|
|
||||||
### Integration with ai.ai Ecosystem
|
|
||||||
|
|
||||||
This deployment enables:
|
|
||||||
- **ai.log**: Comment system with ATProto authentication
|
|
||||||
- **ai.card**: Shared OAuth widget
|
|
||||||
- **ai.gpt**: Memory synchronization via ATProto
|
|
||||||
- **ai.verse**: Future 3D world integration
|
|
||||||
|
|
||||||
### Monitoring
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Monitor tunnel logs
|
|
||||||
cloudflared tunnel --config cloudflared-config.yml run --loglevel debug
|
|
||||||
|
|
||||||
# Monitor blog server
|
|
||||||
tail -f /path/to/blog/logs
|
|
||||||
|
|
||||||
# Check ATProto connectivity
|
|
||||||
curl -I https://log.syui.ai/client-metadata.json
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**🔗 Live URL**: https://log.syui.ai
|
|
||||||
**📊 Status**: Production Ready
|
|
||||||
**🌐 ATProto**: OAuth Enabled
|
|
32
Dockerfile
32
Dockerfile
@@ -1,32 +0,0 @@
|
|||||||
# Multi-stage build for ailog
|
|
||||||
FROM rust:1.75 as builder
|
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
COPY Cargo.toml Cargo.lock ./
|
|
||||||
COPY src ./src
|
|
||||||
|
|
||||||
RUN cargo build --release
|
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
|
||||||
|
|
||||||
# Install runtime dependencies
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy the binary
|
|
||||||
COPY --from=builder /usr/src/app/target/release/ailog /usr/local/bin/ailog
|
|
||||||
|
|
||||||
# Copy blog content
|
|
||||||
COPY my-blog ./blog
|
|
||||||
|
|
||||||
# Build static site
|
|
||||||
RUN ailog build blog
|
|
||||||
|
|
||||||
# Expose port
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
# Run server
|
|
||||||
CMD ["ailog", "serve", "blog"]
|
|
900
README.md
900
README.md
@@ -4,520 +4,556 @@ AI-powered static blog generator with ATProto integration, part of the ai.ai eco
|
|||||||
|
|
||||||
## 🚀 Quick Start
|
## 🚀 Quick Start
|
||||||
|
|
||||||
```bash
|
### Installation & Setup
|
||||||
# Development
|
|
||||||
./run.zsh serve
|
|
||||||
|
|
||||||
# Production (with Cloudflare Tunnel)
|
|
||||||
./run.zsh tunnel
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📋 Commands
|
|
||||||
|
|
||||||
| Command | Description |
|
|
||||||
|---------|-------------|
|
|
||||||
| `./run.zsh c` | Enable Cloudflare tunnel (log.syui.ai) for OAuth |
|
|
||||||
| `./run.zsh o` | Start OAuth web server (port:4173 = log.syui.ai) |
|
|
||||||
| `./run.zsh co` | Start comment system (ATProto stream monitor) |
|
|
||||||
|
|
||||||
## 🏗️ Architecture (Pure Rust + HTML + JS)
|
|
||||||
|
|
||||||
```
|
|
||||||
ai.log/
|
|
||||||
├── oauth/ # 🎯 OAuth files (protected)
|
|
||||||
│ ├── oauth-widget-simple.js # Self-contained OAuth widget
|
|
||||||
│ ├── oauth-simple.html # OAuth authentication page
|
|
||||||
│ ├── client-metadata.json # ATProto configuration
|
|
||||||
│ └── README.md # Usage guide
|
|
||||||
├── my-blog/ # Blog content and templates
|
|
||||||
│ ├── content/posts/ # Markdown blog posts
|
|
||||||
│ ├── templates/ # Tera templates
|
|
||||||
│ ├── static/ # Static assets (OAuth copied here)
|
|
||||||
│ └── public/ # Generated site (build output)
|
|
||||||
├── src/ # Rust blog generator
|
|
||||||
├── scripts/ # Build and deployment scripts
|
|
||||||
└── run.zsh # 🎯 Main build script
|
|
||||||
```
|
|
||||||
|
|
||||||
### ✅ Node.js Dependencies Eliminated
|
|
||||||
- ❌ `package.json` - Removed
|
|
||||||
- ❌ `node_modules/` - Removed
|
|
||||||
- ❌ `npm run build` - Not needed
|
|
||||||
- ✅ Pure JavaScript OAuth implementation
|
|
||||||
- ✅ CDN-free, self-contained code
|
|
||||||
- ✅ Rust-only build process
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📖 Original Features
|
|
||||||
|
|
||||||
[](https://www.rust-lang.org/)
|
|
||||||
[](https://opensource.org/licenses/MIT)
|
|
||||||
|
|
||||||
## 概要
|
|
||||||
|
|
||||||
ai.logは、[Anthropic Docs](https://docs.anthropic.com/)にインスパイアされたモダンなインターフェースを持つ、次世代静的ブログジェネレーターです。ai.gptとの深い統合、ローカルAI機能、atproto OAuth連携により、従来のブログシステムを超えた体験を提供します。
|
|
||||||
|
|
||||||
## 主な特徴
|
|
||||||
|
|
||||||
### 🎨 モダンインターフェース
|
|
||||||
- **Anthropic Docs風デザイン**: プロフェッショナルで読みやすい
|
|
||||||
- **Timeline形式**: BlueskyライクなタイムラインUI
|
|
||||||
- **自動TOC**: 右サイドバーに目次を自動生成
|
|
||||||
- **レスポンシブ**: モバイル・デスクトップ対応
|
|
||||||
|
|
||||||
### 🤖 AI統合機能
|
|
||||||
- **Ask AI**: ローカルLLM(Ollama)による質問応答
|
|
||||||
- **自動翻訳**: 日本語↔英語の自動生成
|
|
||||||
- **AI記事強化**: コンテンツの自動改善
|
|
||||||
- **AIコメント**: 記事への一言コメント生成
|
|
||||||
|
|
||||||
### 🌐 分散SNS連携
|
|
||||||
- **atproto OAuth**: Blueskyアカウントでログイン
|
|
||||||
- **コメントシステム**: 分散SNSコメント
|
|
||||||
- **データ主権**: ユーザーがデータを所有
|
|
||||||
|
|
||||||
### 🔗 エコシステム統合
|
|
||||||
- **ai.gpt**: ドキュメント同期・AI機能連携
|
|
||||||
- **MCP Server**: ai.gptからの操作をサポート
|
|
||||||
- **ai.wiki**: 自動ドキュメント同期
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
### Dual MCP Integration
|
|
||||||
|
|
||||||
**ai.log MCP Server (API Layer)**
|
|
||||||
- **Role**: Independent blog API
|
|
||||||
- **Port**: 8002
|
|
||||||
- **Location**: `./src/mcp/`
|
|
||||||
- **Function**: Core blog generation and management
|
|
||||||
|
|
||||||
**ai.gpt Integration (Server Layer)**
|
|
||||||
- **Role**: AI integration gateway
|
|
||||||
- **Port**: 8001 (within ai.gpt)
|
|
||||||
- **Location**: `../src/aigpt/mcp_server.py`
|
|
||||||
- **Function**: AI memory system + HTTP proxy to ai.log
|
|
||||||
|
|
||||||
### Data Flow
|
|
||||||
```
|
|
||||||
Claude Code → ai.gpt (Server/AI) → ai.log (API/Blog) → Static Site
|
|
||||||
↑ ↑
|
|
||||||
Memory System File Operations
|
|
||||||
Relationship AI Markdown Processing
|
|
||||||
Context Analysis Template Rendering
|
|
||||||
```
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Static Blog Generation**: Inspired by Zola, built with Rust
|
|
||||||
- **AI-Powered Content**: Memory-driven article generation via ai.gpt
|
|
||||||
- **🌍 Ollama Translation**: Multi-language markdown translation with structure preservation
|
|
||||||
- **atproto Integration**: OAuth authentication and comment system (planned)
|
|
||||||
- **MCP Integration**: Seamless Claude Code workflow
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install ailog
|
# 1. Clone repository
|
||||||
|
git clone https://git.syui.ai/ai/log
|
||||||
|
cd log
|
||||||
|
|
||||||
|
# 2. Build ailog
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
# 3. Initialize blog
|
||||||
|
./target/release/ailog init my-blog
|
||||||
|
|
||||||
|
# 4. Create your first post
|
||||||
|
./target/release/ailog new "My First Post"
|
||||||
|
|
||||||
|
# 5. Build static site
|
||||||
|
./target/release/ailog build
|
||||||
|
|
||||||
|
# 6. Serve locally
|
||||||
|
./target/release/ailog serve
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
### Install via Cargo
|
||||||
|
|
||||||
### Standalone Mode
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Initialize a new blog
|
cargo install --path .
|
||||||
ailog init myblog
|
# Now you can use `ailog` command globally
|
||||||
|
|
||||||
# Create a new post
|
|
||||||
ailog new "My First Post"
|
|
||||||
|
|
||||||
# Build the blog
|
|
||||||
ailog build
|
|
||||||
|
|
||||||
# Serve locally
|
|
||||||
ailog serve
|
|
||||||
|
|
||||||
# Start MCP server
|
|
||||||
ailog mcp --port 8002
|
|
||||||
|
|
||||||
# Generate documentation
|
|
||||||
ailog doc readme --with-ai
|
|
||||||
ailog doc api --output ./docs
|
|
||||||
ailog doc structure --include-deps
|
|
||||||
|
|
||||||
# Translate documents (requires Ollama)
|
|
||||||
ailog doc translate --input README.md --target-lang en
|
|
||||||
ailog doc translate --input docs/api.md --target-lang ja --model qwen2.5:latest
|
|
||||||
|
|
||||||
# Clean build files
|
|
||||||
ailog clean
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### AI Ecosystem Integration
|
## 📖 Core Commands
|
||||||
|
|
||||||
When integrated with ai.gpt, use natural language:
|
### Blog Management
|
||||||
- "ブログ記事を書いて" → Triggers `log_ai_content`
|
|
||||||
- "記事一覧を見せて" → Triggers `log_list_posts`
|
```bash
|
||||||
- "ブログをビルドして" → Triggers `log_build_blog`
|
# Project setup
|
||||||
|
ailog init <project-name> # Initialize new blog project
|
||||||
|
ailog new <title> # Create new blog post
|
||||||
|
ailog build # Generate static site with JSON index
|
||||||
|
ailog serve # Start development server
|
||||||
|
ailog clean # Clean build artifacts
|
||||||
|
|
||||||
|
# ATProto authentication
|
||||||
|
ailog auth init # Setup ATProto credentials
|
||||||
|
ailog auth status # Check authentication status
|
||||||
|
ailog auth logout # Clear credentials
|
||||||
|
|
||||||
|
# OAuth app build
|
||||||
|
ailog oauth build <project-dir> # Build OAuth comment system
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stream & AI Features
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start monitoring & AI generation
|
||||||
|
ailog stream start --ai-generate # Monitor blog + auto-generate AI content
|
||||||
|
ailog stream start --daemon # Run as background daemon
|
||||||
|
ailog stream status # Check stream status
|
||||||
|
ailog stream stop # Stop monitoring
|
||||||
|
ailog stream test # Test ATProto API access
|
||||||
|
```
|
||||||
|
|
||||||
### Documentation & Translation
|
### Documentation & Translation
|
||||||
|
|
||||||
Generate comprehensive documentation and translate content:
|
```bash
|
||||||
- "READMEを生成して" → Triggers `log_generate_docs`
|
# Generate documentation
|
||||||
- "APIドキュメントを作成して" → Generates API documentation
|
ailog doc readme --with-ai # Generate enhanced README
|
||||||
- "プロジェクト構造を解析して" → Creates structure documentation
|
ailog doc api --output ./docs # Generate API documentation
|
||||||
- "このファイルを英語に翻訳して" → Triggers `log_translate_document`
|
ailog doc structure --include-deps # Analyze project structure
|
||||||
- "マークダウンを日本語に変換して" → Uses Ollama for translation
|
|
||||||
|
|
||||||
## MCP Tools
|
# AI-powered translation
|
||||||
|
ailog doc translate --input README.md --target-lang en
|
||||||
|
ailog doc translate --input docs/guide.ja.md --target-lang en --model qwen2.5:latest
|
||||||
|
```
|
||||||
|
|
||||||
### ai.log Server (Port 8002)
|
## 🏗️ Architecture
|
||||||
- `create_blog_post` - Create new blog post
|
|
||||||
- `list_blog_posts` - List existing posts
|
|
||||||
- `build_blog` - Build static site
|
|
||||||
- `get_post_content` - Get post by slug
|
|
||||||
- `translate_document` ⭐ - Ollama-powered markdown translation
|
|
||||||
- `generate_documentation` ⭐ - Code analysis and documentation generation
|
|
||||||
|
|
||||||
### ai.gpt Integration (Port 8001)
|
### Project Structure
|
||||||
- `log_create_post` - Proxy to ai.log + error handling
|
|
||||||
- `log_list_posts` - Proxy to ai.log + formatting
|
|
||||||
- `log_build_blog` - Proxy to ai.log + AI features
|
|
||||||
- `log_get_post` - Proxy to ai.log + context
|
|
||||||
- `log_system_status` - Health check for ai.log
|
|
||||||
- `log_ai_content` ⭐ - AI memory → blog content generation
|
|
||||||
- `log_translate_document` 🌍 - Document translation via Ollama
|
|
||||||
- `log_generate_docs` 📚 - Documentation generation
|
|
||||||
|
|
||||||
### Documentation Generation Tools
|
```
|
||||||
- `doc readme` - Generate README.md from project analysis
|
ai.log/
|
||||||
- `doc api` - Generate API documentation
|
├── src/ # Rust static blog generator
|
||||||
- `doc structure` - Analyze and document project structure
|
│ ├── commands/ # CLI command implementations
|
||||||
- `doc changelog` - Generate changelog from git history
|
│ ├── generator.rs # Core blog generation + JSON index
|
||||||
- `doc translate` 🌍 - Multi-language document translation
|
│ ├── mcp/ # MCP server integration
|
||||||
|
│ └── main.rs # CLI entry point
|
||||||
|
├── my-blog/ # Your blog content
|
||||||
|
│ ├── content/posts/ # Markdown blog posts
|
||||||
|
│ ├── templates/ # Tera templates
|
||||||
|
│ ├── static/ # Static assets
|
||||||
|
│ └── public/ # Generated site output
|
||||||
|
├── oauth/ # ATProto comment system
|
||||||
|
│ ├── src/ # TypeScript OAuth app
|
||||||
|
│ ├── dist/ # Built OAuth assets
|
||||||
|
│ └── package.json # Node.js dependencies
|
||||||
|
└── target/ # Rust build output
|
||||||
|
```
|
||||||
|
|
||||||
### Translation Features
|
### Data Flow
|
||||||
- **Language Support**: English, Japanese, Chinese, Korean, Spanish
|
|
||||||
- **Markdown Preservation**: Code blocks, links, images, tables maintained
|
|
||||||
- **Auto-Detection**: Automatically detects Japanese content
|
|
||||||
- **Ollama Integration**: Uses local AI models for privacy and cost-efficiency
|
|
||||||
- **Smart Processing**: Section-by-section translation with structure awareness
|
|
||||||
|
|
||||||
## Configuration
|
```
|
||||||
|
Blog Posts (Markdown) → ailog build → public/
|
||||||
|
├── Static HTML pages
|
||||||
|
└── index.json (API)
|
||||||
|
↓
|
||||||
|
ailog stream start --ai-generate → Monitor index.json
|
||||||
|
↓
|
||||||
|
New posts detected → Ollama AI → ATProto records
|
||||||
|
├── ai.syui.log.chat.lang (translations)
|
||||||
|
└── ai.syui.log.chat.comment (AI comments)
|
||||||
|
↓
|
||||||
|
OAuth app → Display AI-generated content
|
||||||
|
```
|
||||||
|
|
||||||
### ai.log Configuration
|
## 🤖 AI Integration
|
||||||
- Location: `~/.config/syui/ai/log/`
|
|
||||||
- Format: TOML configuration
|
|
||||||
|
|
||||||
### ai.gpt Integration
|
### AI Content Generation
|
||||||
- Configuration: `../config.json`
|
|
||||||
- Auto-detection: ai.log tools enabled when `./log/` directory exists
|
|
||||||
- System prompt: Automatically triggers blog tools for related queries
|
|
||||||
|
|
||||||
## AI Integration Features
|
The `--ai-generate` flag enables automatic AI content generation:
|
||||||
|
|
||||||
### Memory-Driven Content Generation
|
1. **Blog Monitoring**: Monitors `index.json` every 5 minutes
|
||||||
- **Source**: ai.gpt memory system
|
2. **Duplicate Prevention**: Checks existing ATProto collections
|
||||||
- **Process**: Contextual memories → AI analysis → Blog content
|
3. **AI Generation**: Uses Ollama (gemma3:4b) for translations & comments
|
||||||
- **Output**: Structured markdown with personal insights
|
4. **ATProto Storage**: Saves to derived collections (`base.chat.lang`, `base.chat.comment`)
|
||||||
|
|
||||||
### Automatic Workflows
|
```bash
|
||||||
- Daily blog posts from accumulated memories
|
# Start AI generation monitor
|
||||||
- Content enhancement and suggestions
|
ailog stream start --ai-generate
|
||||||
- Related article recommendations
|
|
||||||
- Multi-language content generation
|
|
||||||
|
|
||||||
## atproto Integration (Planned)
|
# Output:
|
||||||
|
# 🤖 Starting AI content generation monitor...
|
||||||
|
# 📡 Blog host: https://syui.ai
|
||||||
|
# 🧠 Ollama host: https://ollama.syui.ai
|
||||||
|
# 🔍 Checking for new blog posts...
|
||||||
|
# ✅ Generated translation for: 静的サイトジェネレータを作った
|
||||||
|
# ✅ Generated comment for: 静的サイトジェネレータを作った
|
||||||
|
```
|
||||||
|
|
||||||
### OAuth 2.0 Authentication
|
### Collection Management
|
||||||
- Client metadata: `public/client-metadata.json`
|
|
||||||
- Comment system integration
|
ailog uses a **simplified collection structure** based on a single base collection name:
|
||||||
- Data sovereignty: Users own their comments
|
|
||||||
- Collection storage in atproto
|
```bash
|
||||||
|
# Single environment variable controls all collections (unified naming)
|
||||||
|
export VITE_OAUTH_COLLECTION="ai.syui.log"
|
||||||
|
|
||||||
|
# Automatically derives:
|
||||||
|
# - ai.syui.log (comments)
|
||||||
|
# - ai.syui.log.user (user management)
|
||||||
|
# - ai.syui.log.chat.lang (AI translations)
|
||||||
|
# - ai.syui.log.chat.comment (AI comments)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Benefits:**
|
||||||
|
- ✅ **Simple**: One variable instead of 5+
|
||||||
|
- ✅ **Consistent**: All collections follow the same pattern
|
||||||
|
- ✅ **Manageable**: Easy systemd/production configuration
|
||||||
|
|
||||||
|
### Ask AI Feature
|
||||||
|
|
||||||
|
Interactive AI chat integrated into blog pages:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Setup Ollama
|
||||||
|
brew install ollama
|
||||||
|
ollama pull gemma2:2b
|
||||||
|
|
||||||
|
# 2. Start with CORS support
|
||||||
|
OLLAMA_ORIGINS="https://example.com" ollama serve
|
||||||
|
|
||||||
|
# 3. Configure AI DID in templates/base.html
|
||||||
|
const aiConfig = {
|
||||||
|
systemPrompt: 'You are a helpful AI assistant.',
|
||||||
|
aiDid: 'did:plc:your-ai-bot-did'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 ATProto Integration
|
||||||
|
|
||||||
|
### OAuth Comment System
|
||||||
|
|
||||||
|
The OAuth app provides ATProto-authenticated commenting:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Build OAuth app
|
||||||
|
cd oauth
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 2. Configure for production
|
||||||
|
ailog oauth build my-blog # Auto-generates .env.production
|
||||||
|
|
||||||
|
# 3. Deploy OAuth assets
|
||||||
|
# Assets are automatically copied to public/ during ailog build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Authentication Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize ATProto authentication
|
||||||
|
ailog auth init
|
||||||
|
|
||||||
|
# Input required:
|
||||||
|
# - Handle (e.g., your.handle.bsky.social)
|
||||||
|
# - Access JWT
|
||||||
|
# - Refresh JWT
|
||||||
|
|
||||||
|
# Check status
|
||||||
|
ailog auth status
|
||||||
|
```
|
||||||
|
|
||||||
|
### Collection Structure
|
||||||
|
|
||||||
|
All ATProto collections are **automatically derived** from a single base name:
|
||||||
|
|
||||||
|
```
|
||||||
|
Base Collection: "ai.syui.log"
|
||||||
|
├── ai.syui.log (user comments)
|
||||||
|
├── ai.syui.log.user (registered commenters)
|
||||||
|
└── ai.syui.log.chat/
|
||||||
|
├── ai.syui.log.chat.lang (AI translations)
|
||||||
|
└── ai.syui.log.chat.comment (AI comments)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Configuration Priority:**
|
||||||
|
1. Environment variable: `VITE_OAUTH_COLLECTION` (unified)
|
||||||
|
2. config.toml: `[oauth] collection = "..."`
|
||||||
|
3. Auto-generated from domain (e.g., `log.syui.ai` → `ai.syui.log`)
|
||||||
|
4. Default: `ai.syui.log`
|
||||||
|
|
||||||
|
### Stream Monitoring
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Monitor ATProto streams for comments
|
||||||
|
ailog stream start
|
||||||
|
|
||||||
|
# Enable AI generation alongside monitoring
|
||||||
|
ailog stream start --ai-generate --daemon
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📱 OAuth App Features
|
||||||
|
|
||||||
|
The OAuth TypeScript app provides:
|
||||||
|
|
||||||
### Comment System
|
### Comment System
|
||||||
- **ATProto Stream Monitoring**: Real-time Jetstream connection monitoring
|
- **Real-time Comments**: ATProto-authenticated commenting
|
||||||
- **Collection Tracking**: Monitors `ai.syui.log` collection for new comments
|
- **User Management**: Automatic user registration
|
||||||
- **User Management**: Automatically adds commenting users to `ai.syui.log.user` collection
|
- **Mobile Responsive**: Optimized for all devices
|
||||||
- **Comment Display**: Fetches and displays comments from registered users
|
- **JSON View**: Technical record inspection
|
||||||
- **OAuth Integration**: atproto account login via Cloudflare tunnel
|
|
||||||
- **Distributed Storage**: Comments stored in user-owned atproto collections
|
|
||||||
|
|
||||||
## Build & Deploy
|
### AI Content Display
|
||||||
|
- **Lang: EN Tab**: AI-generated English translations
|
||||||
|
- **AI Comment Tab**: AI-generated blog insights
|
||||||
|
- **Admin Records**: Fetches from admin DID collections
|
||||||
|
- **Real-time Updates**: Live content refresh
|
||||||
|
|
||||||
### GitHub Actions
|
### Setup & Configuration
|
||||||
```yaml
|
|
||||||
# .github/workflows/gh-pages.yml
|
|
||||||
- name: Build ai.log
|
|
||||||
run: |
|
|
||||||
cd log
|
|
||||||
cargo build --release
|
|
||||||
./target/release/ailog build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Cloudflare Pages
|
|
||||||
- Static output: `./public/`
|
|
||||||
- Automatic deployment on main branch push
|
|
||||||
- AI content generation during build process
|
|
||||||
|
|
||||||
## Development Status
|
|
||||||
|
|
||||||
### ✅ Completed Features
|
|
||||||
- Project structure and Cargo.toml setup
|
|
||||||
- CLI interface (init, new, build, serve, clean, mcp, doc)
|
|
||||||
- Configuration system with TOML support
|
|
||||||
- Markdown parsing with frontmatter support
|
|
||||||
- Template system with Handlebars
|
|
||||||
- Static site generation with posts and pages
|
|
||||||
- Development server with hot reload
|
|
||||||
- **MCP server integration (both layers)**
|
|
||||||
- **ai.gpt integration with 6 tools**
|
|
||||||
- **AI memory system connection**
|
|
||||||
- **📚 Documentation generation from code**
|
|
||||||
- **🔍 Rust project analysis and API extraction**
|
|
||||||
- **📝 README, API docs, and structure analysis**
|
|
||||||
- **🌍 Ollama-powered translation system**
|
|
||||||
- **🚀 Complete MCP integration with ai.gpt**
|
|
||||||
- **📄 Markdown-aware translation preserving structure**
|
|
||||||
- **💬 ATProto comment system with Jetstream monitoring**
|
|
||||||
- **🔄 Real-time comment collection and user management**
|
|
||||||
- **🔐 OAuth 2.1 integration with Cloudflare tunnel**
|
|
||||||
- Test blog with sample content and styling
|
|
||||||
|
|
||||||
### 🚧 In Progress
|
|
||||||
- AI-powered content enhancement pipeline
|
|
||||||
- Advanced comment moderation system
|
|
||||||
|
|
||||||
### 📋 Planned Features
|
|
||||||
- Advanced template customization
|
|
||||||
- Plugin system for extensibility
|
|
||||||
- Real-time comment system
|
|
||||||
- Multi-blog management
|
|
||||||
- VTuber integration (ai.verse connection)
|
|
||||||
|
|
||||||
## Integration with ai Ecosystem
|
|
||||||
|
|
||||||
### System Dependencies
|
|
||||||
- **ai.gpt**: Memory system, relationship tracking, AI provider
|
|
||||||
- **ai.card**: Future cross-system content sharing
|
|
||||||
- **ai.bot**: atproto posting and mention handling
|
|
||||||
- **ai.verse**: 3D world blog representation (future)
|
|
||||||
|
|
||||||
### yui System Compliance
|
|
||||||
- **Uniqueness**: Each blog post tied to individual identity
|
|
||||||
- **Reality Reflection**: Personal memories → digital content
|
|
||||||
- **Irreversibility**: Published content maintains historical integrity
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### 1. Standalone Usage
|
|
||||||
```bash
|
```bash
|
||||||
git clone [repository]
|
cd oauth
|
||||||
cd log
|
|
||||||
cargo run -- init my-blog
|
# Development
|
||||||
cargo run -- new "First Post"
|
npm run dev
|
||||||
cargo run -- build
|
|
||||||
cargo run -- serve
|
# Production build
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Preview production
|
||||||
|
npm run preview
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. AI Ecosystem Integration
|
**Environment Variables:**
|
||||||
```bash
|
```bash
|
||||||
# Start ai.log MCP server
|
# Production (.env.production - auto-generated by ailog oauth build)
|
||||||
cargo run -- mcp --port 8002
|
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
|
||||||
|
|
||||||
# In another terminal, start ai.gpt
|
# Simplified collection configuration (single base collection)
|
||||||
cd ../
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||||
# ai.gpt startup commands
|
|
||||||
|
|
||||||
# Use Claude Code with natural language blog commands
|
# AI Configuration
|
||||||
|
VITE_AI_ENABLED=true
|
||||||
|
VITE_AI_ASK_AI=true
|
||||||
|
VITE_AI_PROVIDER=ollama
|
||||||
|
# ... (other AI settings)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation Generation Features
|
## 🔧 Advanced Features
|
||||||
|
|
||||||
### 📚 Automatic README Generation
|
### JSON Index Generation
|
||||||
```bash
|
|
||||||
# Generate README from project analysis
|
|
||||||
ailog doc readme --source ./src --with-ai
|
|
||||||
|
|
||||||
# Output: Enhanced README.md with:
|
Every `ailog build` generates `/public/index.json`:
|
||||||
# - Project overview and metrics
|
|
||||||
# - Dependency analysis
|
```json
|
||||||
# - Module structure
|
[
|
||||||
# - AI-generated insights
|
{
|
||||||
|
"title": "静的サイトジェネレータを作った",
|
||||||
|
"href": "https://syui.ai/posts/2025-06-06-ailog.html",
|
||||||
|
"formated_time": "Thu Jun 12, 2025",
|
||||||
|
"utc_time": "2025-06-12T00:00:00Z",
|
||||||
|
"tags": ["blog", "rust", "mcp", "atp"],
|
||||||
|
"contents": "Plain text content...",
|
||||||
|
"description": "Excerpt...",
|
||||||
|
"categories": []
|
||||||
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📖 API Documentation
|
This enables:
|
||||||
```bash
|
- **API Access**: Programmatic blog content access
|
||||||
# Generate comprehensive API docs
|
- **Stream Monitoring**: AI generation triggers
|
||||||
ailog doc api --source ./src --format markdown --output ./docs
|
- **Search Integration**: Full-text search capabilities
|
||||||
|
|
||||||
# Creates:
|
### Translation System
|
||||||
# - docs/api.md (main API overview)
|
|
||||||
# - docs/module_name.md (per-module documentation)
|
|
||||||
# - Function signatures and documentation
|
|
||||||
# - Struct/enum definitions
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🏗️ Project Structure Analysis
|
AI-powered document translation with Ollama:
|
||||||
```bash
|
|
||||||
# Analyze and document project structure
|
|
||||||
ailog doc structure --source . --include-deps
|
|
||||||
|
|
||||||
# Generates:
|
|
||||||
# - Directory tree visualization
|
|
||||||
# - File distribution by language
|
|
||||||
# - Dependency graph analysis
|
|
||||||
# - Code metrics and statistics
|
|
||||||
```
|
|
||||||
|
|
||||||
### 📝 Git Changelog Generation
|
|
||||||
```bash
|
|
||||||
# Generate changelog from git history
|
|
||||||
ailog doc changelog --from v1.0.0 --explain-changes
|
|
||||||
|
|
||||||
# Creates:
|
|
||||||
# - Structured changelog
|
|
||||||
# - Commit categorization
|
|
||||||
# - AI-enhanced change explanations
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🤖 AI-Enhanced Documentation
|
|
||||||
When `--with-ai` is enabled:
|
|
||||||
- **Content Enhancement**: AI improves readability and adds insights
|
|
||||||
- **Context Awareness**: Leverages ai.gpt memory system
|
|
||||||
- **Smart Categorization**: Automatic organization of content
|
|
||||||
- **Technical Writing**: Professional documentation style
|
|
||||||
|
|
||||||
## 🌍 Translation System
|
|
||||||
|
|
||||||
### Ollama-Powered Translation
|
|
||||||
|
|
||||||
ai.log includes a comprehensive translation system powered by Ollama AI models:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Basic translation
|
# Basic translation
|
||||||
ailog doc translate --input README.md --target-lang en
|
ailog doc translate --input README.md --target-lang en
|
||||||
|
|
||||||
# Advanced translation with custom settings
|
# Advanced options
|
||||||
ailog doc translate \
|
ailog doc translate \
|
||||||
--input docs/technical-guide.ja.md \
|
--input docs/guide.ja.md \
|
||||||
--target-lang en \
|
--target-lang en \
|
||||||
--source-lang ja \
|
--source-lang ja \
|
||||||
--output docs/technical-guide.en.md \
|
|
||||||
--model qwen2.5:latest \
|
--model qwen2.5:latest \
|
||||||
--ollama-endpoint http://localhost:11434
|
--output docs/guide.en.md
|
||||||
```
|
```
|
||||||
|
|
||||||
### Translation Features
|
**Features:**
|
||||||
|
- **Markdown-aware**: Preserves code blocks, links, tables
|
||||||
|
- **Multiple models**: qwen2.5, gemma3, etc.
|
||||||
|
- **Auto-detection**: Detects Japanese content automatically
|
||||||
|
- **Structure preservation**: Maintains document formatting
|
||||||
|
|
||||||
#### 📄 Markdown-Aware Processing
|
### MCP Server Integration
|
||||||
- **Code Block Preservation**: All code snippets remain untranslated
|
|
||||||
- **Link Maintenance**: URLs and link structures preserved
|
|
||||||
- **Image Handling**: Alt text can be translated while preserving image paths
|
|
||||||
- **Table Translation**: Table content translated while maintaining structure
|
|
||||||
- **Header Preservation**: Markdown headers translated with level maintenance
|
|
||||||
|
|
||||||
#### 🎯 Smart Language Detection
|
```bash
|
||||||
- **Auto-Detection**: Automatically detects Japanese content using Unicode ranges
|
# Start MCP server for ai.gpt integration
|
||||||
- **Manual Override**: Specify source language for precise control
|
ailog mcp --port 8002
|
||||||
- **Mixed Content**: Handles documents with multiple languages
|
|
||||||
|
|
||||||
#### 🔧 Flexible Configuration
|
# Available tools:
|
||||||
- **Model Selection**: Choose from available Ollama models
|
# - create_blog_post
|
||||||
- **Custom Endpoints**: Use different Ollama instances
|
# - list_blog_posts
|
||||||
- **Output Control**: Auto-generate or specify output paths
|
# - build_blog
|
||||||
- **Batch Processing**: Process multiple files efficiently
|
# - get_post_content
|
||||||
|
# - translate_document
|
||||||
|
# - generate_documentation
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 Deployment
|
||||||
|
|
||||||
|
### GitHub Actions
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: Deploy ai.log Blog
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Build ailog
|
||||||
|
run: cargo build --release
|
||||||
|
|
||||||
|
- name: Build blog
|
||||||
|
run: |
|
||||||
|
cd my-blog
|
||||||
|
../target/release/ailog build
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
projectName: my-blog
|
||||||
|
directory: my-blog/public
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Build for production
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
# 2. Setup systemd services
|
||||||
|
sudo cp systemd/system/ailog-stream.service /etc/systemd/system/
|
||||||
|
sudo systemctl enable ailog-stream.service
|
||||||
|
sudo systemctl start ailog-stream.service
|
||||||
|
|
||||||
|
# 3. Configure Ollama with CORS
|
||||||
|
sudo vim /usr/lib/systemd/system/ollama.service
|
||||||
|
# Add: Environment="OLLAMA_ORIGINS=https://yourdomain.com"
|
||||||
|
|
||||||
|
# 4. Monitor services
|
||||||
|
journalctl -u ailog-stream.service -f
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌍 Translation Support
|
||||||
|
|
||||||
### Supported Languages
|
### Supported Languages
|
||||||
|
|
||||||
| Language | Code | Direction | Model Optimized |
|
| Language | Code | Status | Model |
|
||||||
|----------|------|-----------|-----------------|
|
|----------|------|--------|-------|
|
||||||
| English | `en` | ↔️ | ✅ qwen2.5 |
|
| English | `en` | ✅ Full | qwen2.5 |
|
||||||
| Japanese | `ja` | ↔️ | ✅ qwen2.5 |
|
| Japanese | `ja` | ✅ Full | qwen2.5 |
|
||||||
| Chinese | `zh` | ↔️ | ✅ qwen2.5 |
|
| Chinese | `zh` | ✅ Full | qwen2.5 |
|
||||||
| Korean | `ko` | ↔️ | ⚠️ Basic |
|
| Korean | `ko` | ⚠️ Basic | qwen2.5 |
|
||||||
| Spanish | `es` | ↔️ | ⚠️ Basic |
|
| Spanish | `es` | ⚠️ Basic | qwen2.5 |
|
||||||
|
|
||||||
### Translation Workflow
|
### Translation Workflow
|
||||||
|
|
||||||
1. **Parse Document**: Analyze markdown structure and identify sections
|
1. **Parse**: Analyze markdown structure
|
||||||
2. **Preserve Code**: Isolate code blocks and technical content
|
2. **Preserve**: Isolate code blocks and technical content
|
||||||
3. **Translate Content**: Process text sections with Ollama AI
|
3. **Translate**: Process with Ollama AI
|
||||||
4. **Reconstruct**: Rebuild document maintaining original formatting
|
4. **Reconstruct**: Rebuild with original formatting
|
||||||
5. **Validate**: Ensure structural integrity and completeness
|
5. **Validate**: Ensure structural integrity
|
||||||
|
|
||||||
### Integration with ai.gpt
|
## 🎯 Use Cases
|
||||||
|
|
||||||
```python
|
### Personal Blog
|
||||||
# Via ai.gpt MCP tools
|
- **AI-Enhanced**: Automatic translations and AI insights
|
||||||
await log_translate_document(
|
- **Distributed Comments**: ATProto-based social interaction
|
||||||
input_file="README.ja.md",
|
- **Mobile-First**: Responsive OAuth comment system
|
||||||
target_lang="en",
|
|
||||||
model="qwen2.5:latest"
|
### Technical Documentation
|
||||||
)
|
- **Code Analysis**: Automatic API documentation
|
||||||
|
- **Multi-language**: AI-powered translation
|
||||||
|
- **Structure Analysis**: Project overview generation
|
||||||
|
|
||||||
|
### AI Ecosystem Integration
|
||||||
|
- **ai.gpt Connection**: Memory-driven content generation
|
||||||
|
- **MCP Integration**: Claude Code workflow support
|
||||||
|
- **Distributed Identity**: ATProto authentication
|
||||||
|
|
||||||
|
## 🔍 Troubleshooting
|
||||||
|
|
||||||
|
### Build Issues
|
||||||
|
```bash
|
||||||
|
# Check Rust version
|
||||||
|
rustc --version
|
||||||
|
|
||||||
|
# Update dependencies
|
||||||
|
cargo update
|
||||||
|
|
||||||
|
# Clean build
|
||||||
|
cargo clean && cargo build --release
|
||||||
```
|
```
|
||||||
|
|
||||||
### Requirements
|
### Authentication Problems
|
||||||
|
```bash
|
||||||
|
# Reset authentication
|
||||||
|
ailog auth logout
|
||||||
|
ailog auth init
|
||||||
|
|
||||||
- **Ollama**: Install and run Ollama locally
|
# Test API access
|
||||||
- **Models**: Download supported models (qwen2.5:latest recommended)
|
ailog stream test
|
||||||
- **Memory**: Sufficient RAM for model inference
|
```
|
||||||
- **Network**: For initial model download only
|
|
||||||
|
|
||||||
## Configuration Examples
|
### AI Generation Issues
|
||||||
|
```bash
|
||||||
|
# Check Ollama status
|
||||||
|
curl http://localhost:11434/api/tags
|
||||||
|
|
||||||
### Basic Blog Config
|
# Test with manual request
|
||||||
|
curl -X POST http://localhost:11434/api/generate \
|
||||||
|
-d '{"model":"gemma3:4b","prompt":"Test","stream":false}'
|
||||||
|
|
||||||
|
# Check CORS settings
|
||||||
|
# Ensure OLLAMA_ORIGINS includes your domain
|
||||||
|
```
|
||||||
|
|
||||||
|
### OAuth App Issues
|
||||||
|
```bash
|
||||||
|
# Rebuild OAuth assets
|
||||||
|
cd oauth
|
||||||
|
rm -rf dist/
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Check environment variables
|
||||||
|
cat .env.production
|
||||||
|
|
||||||
|
# Verify client-metadata.json
|
||||||
|
curl https://yourdomain.com/client-metadata.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📚 Documentation
|
||||||
|
|
||||||
|
### Core Concepts
|
||||||
|
- **Static Generation**: Rust-powered site building
|
||||||
|
- **JSON Index**: API-compatible blog data
|
||||||
|
- **ATProto Integration**: Distributed social features
|
||||||
|
- **AI Enhancement**: Automatic content generation
|
||||||
|
|
||||||
|
### File Structure
|
||||||
|
- `config.toml`: Blog configuration (simplified collection setup)
|
||||||
|
- `content/posts/*.md`: Blog post sources
|
||||||
|
- `templates/*.html`: Tera template files
|
||||||
|
- `public/`: Generated static site + API (index.json)
|
||||||
|
- `oauth/dist/`: Built OAuth assets
|
||||||
|
|
||||||
|
### Example config.toml
|
||||||
```toml
|
```toml
|
||||||
[blog]
|
[site]
|
||||||
title = "My AI Blog"
|
title = "My Blog"
|
||||||
description = "Personal thoughts and AI insights"
|
base_url = "https://myblog.com"
|
||||||
base_url = "https://myblog.example.com"
|
|
||||||
|
[oauth]
|
||||||
|
admin = "did:plc:your-admin-did"
|
||||||
|
collection = "ai.myblog.log" # Single base collection
|
||||||
|
|
||||||
[ai]
|
[ai]
|
||||||
provider = "openai"
|
enabled = true
|
||||||
model = "gpt-4"
|
auto_translate = true
|
||||||
translation = true
|
comment_moderation = true
|
||||||
|
model = "gemma3:4b"
|
||||||
|
host = "https://ollama.syui.ai"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Advanced Integration
|
## 🔗 ai.ai Ecosystem
|
||||||
```json
|
|
||||||
// ../config.json (ai.gpt)
|
|
||||||
{
|
|
||||||
"mcp": {
|
|
||||||
"servers": {
|
|
||||||
"ai_gpt": {
|
|
||||||
"endpoints": {
|
|
||||||
"log_ai_content": "/log_ai_content",
|
|
||||||
"log_create_post": "/log_create_post"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
ai.log is part of the broader ai.ai ecosystem:
|
||||||
|
|
||||||
### MCP Connection Issues
|
- **ai.gpt**: Memory system and AI integration
|
||||||
- Ensure ai.log server is running: `cargo run -- mcp --port 8002`
|
- **ai.card**: ATProto-based card game system
|
||||||
- Check ai.gpt config includes log endpoints
|
- **ai.bot**: Social media automation
|
||||||
- Verify `./log/` directory exists relative to ai.gpt
|
- **ai.verse**: 3D virtual world integration
|
||||||
|
- **ai.shell**: AI-powered shell interface
|
||||||
|
|
||||||
### Build Failures
|
### yui System Compliance
|
||||||
- Check Rust version: `rustc --version`
|
- **Uniqueness**: Each blog tied to individual identity
|
||||||
- Update dependencies: `cargo update`
|
- **Reality Reflection**: Personal memories → digital content
|
||||||
- Clear cache: `cargo clean`
|
- **Irreversibility**: Published content maintains integrity
|
||||||
|
|
||||||
### AI Integration Problems
|
## 📝 License
|
||||||
- Verify ai.gpt memory system is initialized
|
|
||||||
- Check AI provider configuration
|
|
||||||
- Ensure sufficient context in memory system
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
© syui
|
© syui
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Part of the ai ecosystem**: ai.gpt, ai.card, ai.log, ai.bot, ai.verse, ai.shell
|
**Part of the ai ecosystem**: ai.gpt, ai.card, ai.log, ai.bot, ai.verse, ai.shell
|
@@ -1,4 +0,0 @@
|
|||||||
# Default environment variables (fallback)
|
|
||||||
VITE_APP_HOST=https://log.syui.ai
|
|
||||||
VITE_OAUTH_CLIENT_ID=https://log.syui.ai/client-metadata.json
|
|
||||||
VITE_OAUTH_REDIRECT_URI=https://log.syui.ai/oauth/callback
|
|
@@ -1,4 +0,0 @@
|
|||||||
# Development environment variables
|
|
||||||
VITE_APP_HOST=http://localhost:4173
|
|
||||||
VITE_OAUTH_CLIENT_ID=http://localhost:4173/client-metadata.json
|
|
||||||
VITE_OAUTH_REDIRECT_URI=http://localhost:4173/oauth/callback
|
|
@@ -1,4 +0,0 @@
|
|||||||
# Production environment variables
|
|
||||||
VITE_APP_HOST=https://log.syui.ai
|
|
||||||
VITE_OAUTH_CLIENT_ID=https://log.syui.ai/client-metadata.json
|
|
||||||
VITE_OAUTH_REDIRECT_URI=https://log.syui.ai/oauth/callback
|
|
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"client_id": "https://log.syui.ai/client-metadata.json",
|
|
||||||
"client_name": "ai.card",
|
|
||||||
"client_uri": "https://log.syui.ai",
|
|
||||||
"logo_uri": "https://log.syui.ai/favicon.ico",
|
|
||||||
"tos_uri": "https://log.syui.ai/terms",
|
|
||||||
"policy_uri": "https://log.syui.ai/privacy",
|
|
||||||
"redirect_uris": [
|
|
||||||
"https://log.syui.ai/oauth/callback",
|
|
||||||
"https://log.syui.ai/"
|
|
||||||
],
|
|
||||||
"response_types": [
|
|
||||||
"code"
|
|
||||||
],
|
|
||||||
"grant_types": [
|
|
||||||
"authorization_code",
|
|
||||||
"refresh_token"
|
|
||||||
],
|
|
||||||
"token_endpoint_auth_method": "none",
|
|
||||||
"scope": "atproto transition:generic",
|
|
||||||
"subject_type": "public",
|
|
||||||
"application_type": "web",
|
|
||||||
"dpop_bound_access_tokens": true
|
|
||||||
}
|
|
@@ -1,970 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { OAuthCallback } from './components/OAuthCallback';
|
|
||||||
import { authService, User } from './services/auth';
|
|
||||||
import { atprotoOAuthService } from './services/atproto-oauth';
|
|
||||||
import './App.css';
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
console.log('APP COMPONENT LOADED - Console working!');
|
|
||||||
console.log('Current timestamp:', new Date().toISOString());
|
|
||||||
|
|
||||||
// Immediately log URL information on every page load
|
|
||||||
console.log('IMMEDIATE URL CHECK:');
|
|
||||||
console.log('- href:', window.location.href);
|
|
||||||
console.log('- pathname:', window.location.pathname);
|
|
||||||
console.log('- search:', window.location.search);
|
|
||||||
console.log('- hash:', window.location.hash);
|
|
||||||
|
|
||||||
// Also show URL info via alert if it contains OAuth parameters
|
|
||||||
if (window.location.search.includes('code=') || window.location.search.includes('state=')) {
|
|
||||||
const urlInfo = `OAuth callback detected!\n\nURL: ${window.location.href}\nSearch: ${window.location.search}`;
|
|
||||||
alert(urlInfo);
|
|
||||||
console.log('OAuth callback URL detected!');
|
|
||||||
} else {
|
|
||||||
// Check if we have stored OAuth info from previous steps
|
|
||||||
const preOAuthUrl = sessionStorage.getItem('pre_oauth_url');
|
|
||||||
const storedState = sessionStorage.getItem('oauth_state');
|
|
||||||
const storedCodeVerifier = sessionStorage.getItem('oauth_code_verifier');
|
|
||||||
|
|
||||||
console.log('=== OAUTH SESSION STORAGE CHECK ===');
|
|
||||||
console.log('Pre-OAuth URL:', preOAuthUrl);
|
|
||||||
console.log('Stored state:', storedState);
|
|
||||||
console.log('Stored code verifier:', storedCodeVerifier ? 'Present' : 'Missing');
|
|
||||||
console.log('=== END SESSION STORAGE CHECK ===');
|
|
||||||
}
|
|
||||||
|
|
||||||
const [user, setUser] = useState<User | null>(null);
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [comments, setComments] = useState<any[]>([]);
|
|
||||||
const [commentText, setCommentText] = useState('');
|
|
||||||
const [isPosting, setIsPosting] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [handleInput, setHandleInput] = useState('');
|
|
||||||
const [userListInput, setUserListInput] = useState('');
|
|
||||||
const [isPostingUserList, setIsPostingUserList] = useState(false);
|
|
||||||
const [userListRecords, setUserListRecords] = useState<any[]>([]);
|
|
||||||
const [showJsonFor, setShowJsonFor] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// Setup Jetstream WebSocket for real-time comments (optional)
|
|
||||||
const setupJetstream = () => {
|
|
||||||
try {
|
|
||||||
const ws = new WebSocket('wss://jetstream2.us-east.bsky.network/subscribe');
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log('Jetstream connected');
|
|
||||||
ws.send(JSON.stringify({
|
|
||||||
wantedCollections: ['ai.syui.log']
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
|
||||||
try {
|
|
||||||
const data = JSON.parse(event.data);
|
|
||||||
if (data.collection === 'ai.syui.log' && data.commit?.operation === 'create') {
|
|
||||||
console.log('New comment detected via Jetstream:', data);
|
|
||||||
// Optionally reload comments
|
|
||||||
// loadAllComments(window.location.href);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to parse Jetstream message:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onerror = (err) => {
|
|
||||||
console.warn('Jetstream error:', err);
|
|
||||||
};
|
|
||||||
|
|
||||||
return ws;
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to setup Jetstream:', err);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Jetstream + Cache example
|
|
||||||
const jetstream = setupJetstream();
|
|
||||||
|
|
||||||
// キャッシュからコメント読み込み
|
|
||||||
const loadCachedComments = () => {
|
|
||||||
const cached = localStorage.getItem('cached_comments_' + window.location.pathname);
|
|
||||||
if (cached) {
|
|
||||||
const { comments: cachedComments, timestamp } = JSON.parse(cached);
|
|
||||||
// 5分以内のキャッシュなら使用
|
|
||||||
if (Date.now() - timestamp < 5 * 60 * 1000) {
|
|
||||||
setComments(cachedComments);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// キャッシュがなければ、ATProtoから取得(認証状態に関係なく)
|
|
||||||
if (!loadCachedComments()) {
|
|
||||||
loadAllComments(); // URLフィルタリングを無効にして全コメント表示
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle popstate events for mock OAuth flow
|
|
||||||
const handlePopState = () => {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const isOAuthCallback = urlParams.has('code') && urlParams.has('state');
|
|
||||||
|
|
||||||
if (isOAuthCallback) {
|
|
||||||
// Force re-render to handle OAuth callback
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('popstate', handlePopState);
|
|
||||||
|
|
||||||
// Check if this is an OAuth callback
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const isOAuthCallback = urlParams.has('code') && urlParams.has('state');
|
|
||||||
|
|
||||||
if (isOAuthCallback) {
|
|
||||||
return; // Let OAuthCallback component handle this
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check existing sessions
|
|
||||||
const checkAuth = async () => {
|
|
||||||
// First check OAuth session using official BrowserOAuthClient
|
|
||||||
console.log('Checking OAuth session...');
|
|
||||||
const oauthResult = await atprotoOAuthService.checkSession();
|
|
||||||
console.log('OAuth checkSession result:', oauthResult);
|
|
||||||
|
|
||||||
if (oauthResult) {
|
|
||||||
console.log('OAuth session found:', oauthResult);
|
|
||||||
// Ensure handle is not DID
|
|
||||||
const handle = oauthResult.handle !== oauthResult.did ? oauthResult.handle : oauthResult.handle;
|
|
||||||
|
|
||||||
// Get user profile including avatar
|
|
||||||
const userProfile = await getUserProfile(oauthResult.did, handle);
|
|
||||||
setUser(userProfile);
|
|
||||||
|
|
||||||
// Load all comments for display (this will be the default view)
|
|
||||||
// Temporarily disable URL filtering to see all comments
|
|
||||||
loadAllComments();
|
|
||||||
|
|
||||||
// Load user list records if admin
|
|
||||||
if (userProfile.did === 'did:plc:uqzpqmrjnptsxezjx4xuh2mn') {
|
|
||||||
loadUserListRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
console.log('No OAuth session found');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to legacy auth
|
|
||||||
const verifiedUser = await authService.verify();
|
|
||||||
if (verifiedUser) {
|
|
||||||
setUser(verifiedUser);
|
|
||||||
|
|
||||||
// Load all comments for display (this will be the default view)
|
|
||||||
// Temporarily disable URL filtering to see all comments
|
|
||||||
loadAllComments();
|
|
||||||
|
|
||||||
// Load user list records if admin
|
|
||||||
if (verifiedUser.did === 'did:plc:uqzpqmrjnptsxezjx4xuh2mn') {
|
|
||||||
loadUserListRecords();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setIsLoading(false);
|
|
||||||
|
|
||||||
// 認証状態に関係なく、コメントを読み込む
|
|
||||||
loadAllComments();
|
|
||||||
};
|
|
||||||
|
|
||||||
checkAuth();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('popstate', handlePopState);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const getUserProfile = async (did: string, handle: string): Promise<User> => {
|
|
||||||
try {
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (agent) {
|
|
||||||
const profile = await agent.getProfile({ actor: handle });
|
|
||||||
return {
|
|
||||||
did: did,
|
|
||||||
handle: handle,
|
|
||||||
avatar: profile.data.avatar,
|
|
||||||
displayName: profile.data.displayName || handle
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to get user profile:', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to basic user info
|
|
||||||
return {
|
|
||||||
did: did,
|
|
||||||
handle: handle,
|
|
||||||
avatar: generatePlaceholderAvatar(handle),
|
|
||||||
displayName: handle
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const generatePlaceholderAvatar = (handle: string): string => {
|
|
||||||
const initial = handle ? handle.charAt(0).toUpperCase() : 'U';
|
|
||||||
return `https://via.placeholder.com/48x48/1185fe/ffffff?text=${initial}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadUserComments = async (did: string) => {
|
|
||||||
try {
|
|
||||||
console.log('Loading comments for DID:', did);
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (!agent) {
|
|
||||||
console.log('No agent available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get comments from current user
|
|
||||||
const response = await agent.api.com.atproto.repo.listRecords({
|
|
||||||
repo: did,
|
|
||||||
collection: 'ai.syui.log',
|
|
||||||
limit: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('User comments loaded:', response.data);
|
|
||||||
const userComments = response.data.records || [];
|
|
||||||
|
|
||||||
// Enhance comments with profile information if missing
|
|
||||||
const enhancedComments = await Promise.all(
|
|
||||||
userComments.map(async (record) => {
|
|
||||||
if (!record.value.author?.avatar && record.value.author?.handle) {
|
|
||||||
try {
|
|
||||||
const profile = await agent.getProfile({ actor: record.value.author.handle });
|
|
||||||
return {
|
|
||||||
...record,
|
|
||||||
value: {
|
|
||||||
...record.value,
|
|
||||||
author: {
|
|
||||||
...record.value.author,
|
|
||||||
avatar: profile.data.avatar,
|
|
||||||
displayName: profile.data.displayName || record.value.author.handle,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to enhance comment with profile:', err);
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return record;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
setComments(enhancedComments);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load comments:', err);
|
|
||||||
setComments([]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// JSONからユーザーリストを取得
|
|
||||||
const loadUsersFromRecord = async () => {
|
|
||||||
try {
|
|
||||||
// 管理者のユーザーリストを取得 (ai.syui.log.user collection)
|
|
||||||
const adminDid = 'did:plc:uqzpqmrjnptsxezjx4xuh2mn'; // syui.ai
|
|
||||||
console.log('Fetching user list from admin DID:', adminDid);
|
|
||||||
const response = await fetch(`https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=ai.syui.log.user&limit=100`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
console.warn('Failed to fetch user list from admin, using default users. Status:', response.status);
|
|
||||||
return getDefaultUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const userRecords = data.records || [];
|
|
||||||
console.log('User records found:', userRecords.length);
|
|
||||||
|
|
||||||
if (userRecords.length === 0) {
|
|
||||||
console.log('No user records found, using default users');
|
|
||||||
return getDefaultUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
// レコードからユーザーリストを構築し、プレースホルダーDIDを実際のDIDに解決
|
|
||||||
const allUsers = [];
|
|
||||||
for (const record of userRecords) {
|
|
||||||
if (record.value.users) {
|
|
||||||
// プレースホルダーDIDを実際のDIDに解決
|
|
||||||
const resolvedUsers = await Promise.all(
|
|
||||||
record.value.users.map(async (user) => {
|
|
||||||
if (user.did && user.did.includes('-placeholder')) {
|
|
||||||
console.log(`Resolving placeholder DID for ${user.handle}`);
|
|
||||||
try {
|
|
||||||
const profileResponse = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`);
|
|
||||||
if (profileResponse.ok) {
|
|
||||||
const profileData = await profileResponse.json();
|
|
||||||
if (profileData.did) {
|
|
||||||
console.log(`Resolved ${user.handle}: ${user.did} -> ${profileData.did}`);
|
|
||||||
return {
|
|
||||||
...user,
|
|
||||||
did: profileData.did
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`Failed to resolve DID for ${user.handle}:`, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
allUsers.push(...resolvedUsers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Loaded and resolved users from admin records:', allUsers);
|
|
||||||
return allUsers;
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to load users from records, using defaults:', err);
|
|
||||||
return getDefaultUsers();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// ユーザーリスト一覧を読み込み
|
|
||||||
const loadUserListRecords = async () => {
|
|
||||||
try {
|
|
||||||
console.log('Loading user list records...');
|
|
||||||
const adminDid = 'did:plc:uqzpqmrjnptsxezjx4xuh2mn'; // syui.ai
|
|
||||||
const response = await fetch(`https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=ai.syui.log.user&limit=100`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
console.warn('Failed to fetch user list records');
|
|
||||||
setUserListRecords([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const records = data.records || [];
|
|
||||||
|
|
||||||
// 新しい順にソート
|
|
||||||
const sortedRecords = records.sort((a, b) =>
|
|
||||||
new Date(b.value.createdAt).getTime() - new Date(a.value.createdAt).getTime()
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`Loaded ${sortedRecords.length} user list records`);
|
|
||||||
setUserListRecords(sortedRecords);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load user list records:', err);
|
|
||||||
setUserListRecords([]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDefaultUsers = () => {
|
|
||||||
const defaultUsers = [
|
|
||||||
// bsky.social - 実際のDIDを使用
|
|
||||||
{ did: 'did:plc:uqzpqmrjnptsxezjx4xuh2mn', handle: 'syui.ai', pds: 'https://bsky.social' },
|
|
||||||
];
|
|
||||||
|
|
||||||
// 現在ログインしているユーザーも追加(重複チェック)
|
|
||||||
if (user && user.did && user.handle && !defaultUsers.find(u => u.did === user.did)) {
|
|
||||||
defaultUsers.push({
|
|
||||||
did: user.did,
|
|
||||||
handle: user.handle,
|
|
||||||
pds: user.handle.endsWith('.syu.is') ? 'https://syu.is' : 'https://bsky.social'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Default users list (including current user):', defaultUsers);
|
|
||||||
return defaultUsers;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 新しい関数: 全ユーザーからコメントを収集
|
|
||||||
const loadAllComments = async (pageUrl?: string) => {
|
|
||||||
try {
|
|
||||||
console.log('Loading comments from all users...');
|
|
||||||
console.log('Page URL filter:', pageUrl);
|
|
||||||
|
|
||||||
// ユーザーリストを動的に取得
|
|
||||||
const knownUsers = await loadUsersFromRecord();
|
|
||||||
console.log('Known users for comment fetching:', knownUsers);
|
|
||||||
|
|
||||||
const allComments = [];
|
|
||||||
|
|
||||||
// 各ユーザーからコメントを収集
|
|
||||||
for (const user of knownUsers) {
|
|
||||||
try {
|
|
||||||
console.log(`Fetching comments from user: ${user.handle} (${user.did}) at ${user.pds}`);
|
|
||||||
|
|
||||||
// Public API使用(認証不要)
|
|
||||||
const response = await fetch(`${user.pds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(user.did)}&collection=ai.syui.log&limit=100`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
console.warn(`Failed to fetch from ${user.handle} (${response.status}): ${response.statusText}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const userComments = data.records || [];
|
|
||||||
console.log(`Found ${userComments.length} comments from ${user.handle}`);
|
|
||||||
|
|
||||||
// ページURLでフィルタリング(指定された場合)
|
|
||||||
const filteredComments = pageUrl
|
|
||||||
? userComments.filter(record => record.value.url === pageUrl)
|
|
||||||
: userComments;
|
|
||||||
|
|
||||||
console.log(`After URL filtering (${pageUrl}): ${filteredComments.length} comments from ${user.handle}`);
|
|
||||||
console.log('All comments from this user:', userComments.map(r => ({ url: r.value.url, text: r.value.text })));
|
|
||||||
allComments.push(...filteredComments);
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`Failed to load comments from ${user.handle}:`, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 時間順にソート(新しい順)
|
|
||||||
const sortedComments = allComments.sort((a, b) =>
|
|
||||||
new Date(b.value.createdAt).getTime() - new Date(a.value.createdAt).getTime()
|
|
||||||
);
|
|
||||||
|
|
||||||
// プロフィール情報で拡張(認証なしでも取得可能)
|
|
||||||
const enhancedComments = await Promise.all(
|
|
||||||
sortedComments.map(async (record) => {
|
|
||||||
if (!record.value.author?.avatar && record.value.author?.handle) {
|
|
||||||
try {
|
|
||||||
// Public API でプロフィール取得
|
|
||||||
const profileResponse = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`);
|
|
||||||
|
|
||||||
if (profileResponse.ok) {
|
|
||||||
const profileData = await profileResponse.json();
|
|
||||||
return {
|
|
||||||
...record,
|
|
||||||
value: {
|
|
||||||
...record.value,
|
|
||||||
author: {
|
|
||||||
...record.value.author,
|
|
||||||
avatar: profileData.avatar,
|
|
||||||
displayName: profileData.displayName || record.value.author.handle,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to enhance comment with profile:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return record;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`Loaded ${enhancedComments.length} comments from all users`);
|
|
||||||
|
|
||||||
// デバッグ情報を追加
|
|
||||||
console.log('Final enhanced comments:', enhancedComments);
|
|
||||||
console.log('Known users used:', knownUsers);
|
|
||||||
|
|
||||||
setComments(enhancedComments);
|
|
||||||
|
|
||||||
// キャッシュに保存(5分間有効)
|
|
||||||
if (pageUrl) {
|
|
||||||
const cacheKey = 'cached_comments_' + new URL(pageUrl).pathname;
|
|
||||||
const cacheData = {
|
|
||||||
comments: enhancedComments,
|
|
||||||
timestamp: Date.now()
|
|
||||||
};
|
|
||||||
localStorage.setItem(cacheKey, JSON.stringify(cacheData));
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load all comments:', err);
|
|
||||||
setComments([]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const handlePostComment = async () => {
|
|
||||||
if (!user || !commentText.trim()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsPosting(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (!agent) {
|
|
||||||
throw new Error('No agent available');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create comment record with ISO datetime rkey
|
|
||||||
const now = new Date();
|
|
||||||
const rkey = now.toISOString().replace(/[:.]/g, '-'); // Replace : and . with - for valid rkey
|
|
||||||
|
|
||||||
const record = {
|
|
||||||
$type: 'ai.syui.log',
|
|
||||||
text: commentText,
|
|
||||||
url: window.location.href,
|
|
||||||
createdAt: now.toISOString(),
|
|
||||||
author: {
|
|
||||||
did: user.did,
|
|
||||||
handle: user.handle,
|
|
||||||
avatar: user.avatar,
|
|
||||||
displayName: user.displayName || user.handle,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Post to ATProto with rkey
|
|
||||||
const response = await agent.api.com.atproto.repo.putRecord({
|
|
||||||
repo: user.did,
|
|
||||||
collection: 'ai.syui.log',
|
|
||||||
rkey: rkey,
|
|
||||||
record: record,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Comment posted:', response);
|
|
||||||
|
|
||||||
// Clear form and reload all comments
|
|
||||||
setCommentText('');
|
|
||||||
await loadAllComments(window.location.href);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Failed to post comment:', err);
|
|
||||||
setError('コメントの投稿に失敗しました: ' + err.message);
|
|
||||||
} finally {
|
|
||||||
setIsPosting(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteComment = async (uri: string) => {
|
|
||||||
if (!user) {
|
|
||||||
alert('ログインが必要です');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!confirm('このコメントを削除しますか?')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (!agent) {
|
|
||||||
throw new Error('No agent available');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract rkey from URI: at://did:plc:xxx/ai.syui.log/rkey
|
|
||||||
const uriParts = uri.split('/');
|
|
||||||
const rkey = uriParts[uriParts.length - 1];
|
|
||||||
|
|
||||||
console.log('Deleting comment with rkey:', rkey);
|
|
||||||
|
|
||||||
// Delete the record
|
|
||||||
await agent.api.com.atproto.repo.deleteRecord({
|
|
||||||
repo: user.did,
|
|
||||||
collection: 'ai.syui.log',
|
|
||||||
rkey: rkey,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Comment deleted successfully');
|
|
||||||
|
|
||||||
// Reload all comments to reflect the deletion
|
|
||||||
await loadAllComments(window.location.href);
|
|
||||||
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Failed to delete comment:', err);
|
|
||||||
alert('コメントの削除に失敗しました: ' + err.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLogout = async () => {
|
|
||||||
// Logout from both services
|
|
||||||
await authService.logout();
|
|
||||||
atprotoOAuthService.logout();
|
|
||||||
setUser(null);
|
|
||||||
setComments([]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 管理者チェック
|
|
||||||
const isAdmin = (user: User | null): boolean => {
|
|
||||||
return user?.did === 'did:plc:uqzpqmrjnptsxezjx4xuh2mn'; // syui.ai
|
|
||||||
};
|
|
||||||
|
|
||||||
// ユーザーリスト投稿
|
|
||||||
const handlePostUserList = async () => {
|
|
||||||
if (!user || !userListInput.trim()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isAdmin(user)) {
|
|
||||||
alert('管理者のみがユーザーリストを更新できます');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsPostingUserList(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (!agent) {
|
|
||||||
throw new Error('No agent available');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ユーザーリストをパース
|
|
||||||
const userHandles = userListInput
|
|
||||||
.split(',')
|
|
||||||
.map(handle => handle.trim())
|
|
||||||
.filter(handle => handle.length > 0);
|
|
||||||
|
|
||||||
// ユーザーリストを各PDS用に分類し、実際のDIDを解決
|
|
||||||
const users = await Promise.all(userHandles.map(async (handle) => {
|
|
||||||
const pds = handle.endsWith('.syu.is') ? 'https://syu.is' : 'https://bsky.social';
|
|
||||||
|
|
||||||
// 実際のDIDを解決
|
|
||||||
let resolvedDid = `did:plc:${handle.replace(/\./g, '-')}-placeholder`; // フォールバック
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Public APIでプロフィールを取得してDIDを解決
|
|
||||||
const profileResponse = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`);
|
|
||||||
if (profileResponse.ok) {
|
|
||||||
const profileData = await profileResponse.json();
|
|
||||||
if (profileData.did) {
|
|
||||||
resolvedDid = profileData.did;
|
|
||||||
console.log(`Resolved ${handle} -> ${resolvedDid}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`Failed to resolve DID for ${handle}:`, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
handle: handle,
|
|
||||||
pds: pds,
|
|
||||||
did: resolvedDid
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Create user list record with ISO datetime rkey
|
|
||||||
const now = new Date();
|
|
||||||
const rkey = now.toISOString().replace(/[:.]/g, '-');
|
|
||||||
|
|
||||||
const record = {
|
|
||||||
$type: 'ai.syui.log.user',
|
|
||||||
users: users,
|
|
||||||
createdAt: now.toISOString(),
|
|
||||||
updatedBy: {
|
|
||||||
did: user.did,
|
|
||||||
handle: user.handle,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Post to ATProto with rkey
|
|
||||||
const response = await agent.api.com.atproto.repo.putRecord({
|
|
||||||
repo: user.did,
|
|
||||||
collection: 'ai.syui.log.user',
|
|
||||||
rkey: rkey,
|
|
||||||
record: record,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('User list posted:', response);
|
|
||||||
|
|
||||||
// Clear form and reload user list records
|
|
||||||
setUserListInput('');
|
|
||||||
loadUserListRecords();
|
|
||||||
alert('ユーザーリストが更新されました');
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Failed to post user list:', err);
|
|
||||||
setError('ユーザーリストの投稿に失敗しました: ' + err.message);
|
|
||||||
} finally {
|
|
||||||
setIsPostingUserList(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// ユーザーリスト削除
|
|
||||||
const handleDeleteUserList = async (uri: string) => {
|
|
||||||
if (!user || !isAdmin(user)) {
|
|
||||||
alert('管理者のみがユーザーリストを削除できます');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!confirm('このユーザーリストを削除しますか?')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const agent = atprotoOAuthService.getAgent();
|
|
||||||
if (!agent) {
|
|
||||||
throw new Error('No agent available');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract rkey from URI
|
|
||||||
const uriParts = uri.split('/');
|
|
||||||
const rkey = uriParts[uriParts.length - 1];
|
|
||||||
|
|
||||||
console.log('Deleting user list with rkey:', rkey);
|
|
||||||
|
|
||||||
// Delete the record
|
|
||||||
await agent.api.com.atproto.repo.deleteRecord({
|
|
||||||
repo: user.did,
|
|
||||||
collection: 'ai.syui.log.user',
|
|
||||||
rkey: rkey,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('User list deleted successfully');
|
|
||||||
loadUserListRecords();
|
|
||||||
alert('ユーザーリストが削除されました');
|
|
||||||
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Failed to delete user list:', err);
|
|
||||||
alert('ユーザーリストの削除に失敗しました: ' + err.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// JSON表示のトグル
|
|
||||||
const toggleJsonDisplay = (uri: string) => {
|
|
||||||
if (showJsonFor === uri) {
|
|
||||||
setShowJsonFor(null);
|
|
||||||
} else {
|
|
||||||
setShowJsonFor(uri);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// OAuth callback is now handled by React Router in main.tsx
|
|
||||||
console.log('=== APP.TSX URL CHECK ===');
|
|
||||||
console.log('Full URL:', window.location.href);
|
|
||||||
console.log('Pathname:', window.location.pathname);
|
|
||||||
console.log('Search params:', window.location.search);
|
|
||||||
console.log('=== END URL CHECK ===');
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="app">
|
|
||||||
|
|
||||||
<main className="app-main">
|
|
||||||
<section className="comment-section">
|
|
||||||
{/* Authentication Section */}
|
|
||||||
{!user ? (
|
|
||||||
<div className="auth-section">
|
|
||||||
<button
|
|
||||||
onClick={async () => {
|
|
||||||
if (!handleInput.trim()) {
|
|
||||||
alert('Please enter your Bluesky handle first');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await atprotoOAuthService.initiateOAuthFlow(handleInput);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('OAuth failed:', err);
|
|
||||||
alert('認証の開始に失敗しました。再度お試しください。');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="atproto-button"
|
|
||||||
>
|
|
||||||
atproto
|
|
||||||
</button>
|
|
||||||
<div className="username-input-section">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="user.bsky.social"
|
|
||||||
className="handle-input"
|
|
||||||
value={handleInput}
|
|
||||||
onChange={(e) => setHandleInput(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="user-section">
|
|
||||||
<div className="user-info">
|
|
||||||
<div className="user-profile">
|
|
||||||
<img
|
|
||||||
src={user.avatar || generatePlaceholderAvatar(user.handle)}
|
|
||||||
alt="User Avatar"
|
|
||||||
className="user-avatar"
|
|
||||||
/>
|
|
||||||
<div className="user-details">
|
|
||||||
<h3>{user.displayName || user.handle}</h3>
|
|
||||||
<p className="user-handle">@{user.handle}</p>
|
|
||||||
<p className="user-did">DID: {user.did}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button onClick={handleLogout} className="logout-button">
|
|
||||||
Logout
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Admin Section - User Management */}
|
|
||||||
{isAdmin(user) && (
|
|
||||||
<div className="admin-section">
|
|
||||||
<h3>管理者機能 - ユーザーリスト管理</h3>
|
|
||||||
|
|
||||||
{/* User List Form */}
|
|
||||||
<div className="user-list-form">
|
|
||||||
<textarea
|
|
||||||
value={userListInput}
|
|
||||||
onChange={(e) => setUserListInput(e.target.value)}
|
|
||||||
placeholder="ユーザーハンドルをカンマ区切りで入力 例: syui.ai, yui.syui.ai, user.bsky.social"
|
|
||||||
rows={3}
|
|
||||||
disabled={isPostingUserList}
|
|
||||||
/>
|
|
||||||
<div className="form-actions">
|
|
||||||
<span className="admin-hint">カンマ区切りでハンドルを入力してください</span>
|
|
||||||
<button
|
|
||||||
onClick={handlePostUserList}
|
|
||||||
disabled={isPostingUserList || !userListInput.trim()}
|
|
||||||
className="post-button"
|
|
||||||
>
|
|
||||||
{isPostingUserList ? 'Posting...' : 'Post User List'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* User List Records */}
|
|
||||||
<div className="user-list-records">
|
|
||||||
<h4>ユーザーリスト一覧 ({userListRecords.length}件)</h4>
|
|
||||||
{userListRecords.length === 0 ? (
|
|
||||||
<p className="no-user-lists">ユーザーリストが見つかりません</p>
|
|
||||||
) : (
|
|
||||||
userListRecords.map((record, index) => (
|
|
||||||
<div key={index} className="user-list-item">
|
|
||||||
<div className="user-list-header">
|
|
||||||
<span className="user-list-date">
|
|
||||||
{new Date(record.value.createdAt).toLocaleString()}
|
|
||||||
</span>
|
|
||||||
<div className="user-list-actions">
|
|
||||||
<button
|
|
||||||
onClick={() => toggleJsonDisplay(record.uri)}
|
|
||||||
className="json-button"
|
|
||||||
title="Show/Hide JSON"
|
|
||||||
>
|
|
||||||
{showJsonFor === record.uri ? '📄 Hide JSON' : '📄 Show JSON'}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => handleDeleteUserList(record.uri)}
|
|
||||||
className="delete-button"
|
|
||||||
title="Delete user list"
|
|
||||||
>
|
|
||||||
🗑️
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="user-list-content">
|
|
||||||
<div className="user-handles">
|
|
||||||
{record.value.users && record.value.users.map((user, userIndex) => (
|
|
||||||
<span key={userIndex} className="user-handle-tag">
|
|
||||||
{user.handle}
|
|
||||||
<small className="pds-info">({new URL(user.pds).hostname})</small>
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="user-list-meta">
|
|
||||||
<small>URI: {record.uri}</small>
|
|
||||||
<br />
|
|
||||||
<small>Updated by: {record.value.updatedBy?.handle || 'unknown'}</small>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* JSON Display */}
|
|
||||||
{showJsonFor === record.uri && (
|
|
||||||
<div className="json-display">
|
|
||||||
<h5>JSON Record:</h5>
|
|
||||||
<pre className="json-content">
|
|
||||||
{JSON.stringify(record, null, 2)}
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Comments List */}
|
|
||||||
<div className="comments-list">
|
|
||||||
<div className="comments-header">
|
|
||||||
<h3>Comments</h3>
|
|
||||||
<div className="comments-controls">
|
|
||||||
<button
|
|
||||||
onClick={() => user && loadUserComments(user.did)}
|
|
||||||
className="comments-toggle-button"
|
|
||||||
disabled={!user}
|
|
||||||
title={!user ? "Login required to view your comments" : ""}
|
|
||||||
>
|
|
||||||
My Comments {!user && "(Login Required)"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => loadAllComments()}
|
|
||||||
className="comments-toggle-button"
|
|
||||||
>
|
|
||||||
All Comments (No Filter)
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{comments.length === 0 ? (
|
|
||||||
<p className="no-comments">No comments yet</p>
|
|
||||||
) : (
|
|
||||||
comments.map((record, index) => (
|
|
||||||
<div key={index} className="comment-item">
|
|
||||||
<div className="comment-header">
|
|
||||||
<img
|
|
||||||
src={record.value.author?.avatar || generatePlaceholderAvatar(record.value.author?.handle || 'unknown')}
|
|
||||||
alt="User Avatar"
|
|
||||||
className="comment-avatar"
|
|
||||||
/>
|
|
||||||
<div className="comment-author-info">
|
|
||||||
<span className="comment-author">
|
|
||||||
{record.value.author?.displayName || record.value.author?.handle || 'unknown'}
|
|
||||||
</span>
|
|
||||||
<span className="comment-handle">@{record.value.author?.handle || 'unknown'}</span>
|
|
||||||
</div>
|
|
||||||
<span className="comment-date">
|
|
||||||
{new Date(record.value.createdAt).toLocaleString()}
|
|
||||||
</span>
|
|
||||||
{/* Show delete button only for current user's comments */}
|
|
||||||
{user && record.value.author?.did === user.did && (
|
|
||||||
<button
|
|
||||||
onClick={() => handleDeleteComment(record.uri)}
|
|
||||||
className="delete-button"
|
|
||||||
title="Delete comment"
|
|
||||||
>
|
|
||||||
🗑️
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="comment-content">
|
|
||||||
{record.value.text}
|
|
||||||
</div>
|
|
||||||
<div className="comment-meta">
|
|
||||||
<small>URI: {record.uri}</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Comment Form - Outside user section, after comments list */}
|
|
||||||
{user && (
|
|
||||||
<div className="comment-form">
|
|
||||||
<h3>Post a Comment</h3>
|
|
||||||
<textarea
|
|
||||||
value={commentText}
|
|
||||||
onChange={(e) => setCommentText(e.target.value)}
|
|
||||||
placeholder="Write your comment..."
|
|
||||||
rows={4}
|
|
||||||
disabled={isPosting}
|
|
||||||
/>
|
|
||||||
<div className="form-actions">
|
|
||||||
<span className="char-count">{commentText.length} / 1000</span>
|
|
||||||
<button
|
|
||||||
onClick={handlePostComment}
|
|
||||||
disabled={isPosting || !commentText.trim() || commentText.length > 1000}
|
|
||||||
className="post-button"
|
|
||||||
>
|
|
||||||
{isPosting ? 'Posting...' : 'Post Comment'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{error && <p className="error">{error}</p>}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</section>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
@@ -1,23 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import ReactDOM from 'react-dom/client'
|
|
||||||
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
||||||
import App from './App'
|
|
||||||
import { OAuthCallbackPage } from './components/OAuthCallbackPage'
|
|
||||||
import { CardList } from './components/CardList'
|
|
||||||
import { OAuthEndpointHandler } from './utils/oauth-endpoints'
|
|
||||||
|
|
||||||
// Initialize OAuth endpoint handlers for dynamic client metadata and JWKS
|
|
||||||
// DISABLED: This may interfere with BrowserOAuthClient
|
|
||||||
// OAuthEndpointHandler.init()
|
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('comment-atproto')!).render(
|
|
||||||
<React.StrictMode>
|
|
||||||
<BrowserRouter>
|
|
||||||
<Routes>
|
|
||||||
<Route path="/oauth/callback" element={<OAuthCallbackPage />} />
|
|
||||||
<Route path="/list" element={<CardList />} />
|
|
||||||
<Route path="*" element={<App />} />
|
|
||||||
</Routes>
|
|
||||||
</BrowserRouter>
|
|
||||||
</React.StrictMode>,
|
|
||||||
)
|
|
BIN
bin/ailog-linux-x86_64.tar.gz
Normal file
BIN
bin/ailog-linux-x86_64.tar.gz
Normal file
Binary file not shown.
222
claude.md
222
claude.md
@@ -1,5 +1,227 @@
|
|||||||
# エコシステム統合設計書
|
# エコシステム統合設計書
|
||||||
|
|
||||||
|
## 注意事項
|
||||||
|
|
||||||
|
`console.log`は絶対に書かないようにしてください。
|
||||||
|
|
||||||
|
ハードコードしないようにしてください。必ず、`./my-blog/config.toml`や`./oauth/.env.production`を使用するように。または`~/.config/syui/ai/log/config.json`を使用するように。
|
||||||
|
|
||||||
|
重複する名前のenvを作らないようにしてください。新しい環境変数を作る際は必ず検討してください。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# ダメな例
|
||||||
|
VITE_OAUTH_COLLECTION_USER=ai.syui.log.user
|
||||||
|
VITE_OAUTH_COLLECTION_CHAT=ai.syui.log.chat
|
||||||
|
```
|
||||||
|
|
||||||
|
## oauth appの設計
|
||||||
|
|
||||||
|
> ./oauth/.env.production
|
||||||
|
|
||||||
|
```sh
|
||||||
|
VITE_ATPROTO_PDS=syu.is
|
||||||
|
VITE_ADMIN_HANDLE=ai.syui.ai
|
||||||
|
VITE_AI_HANDLE=ai.syui.ai
|
||||||
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||||
|
```
|
||||||
|
|
||||||
|
これらは非常にシンプルな流れになっており、すべての項目は、共通します。短縮できる場合があります。handleは変わる可能性があるので、できる限りdidを使いましょう。
|
||||||
|
|
||||||
|
1. handleからpds, didを取得できる ... com.atproto.repo.describeRepo
|
||||||
|
2. pdsが分かれば、pdsApi, bskyApi, plcApiを割り当てられる
|
||||||
|
3. bskyApiが分かれば、getProfileでavatar-uriを取得できる ... app.bsky.actor.getProfile
|
||||||
|
4. pdsAPiからアカウントにあるcollectionのrecordの情報を取得できる ... com.atproto.repo.listRecords
|
||||||
|
|
||||||
|
### コメントを表示する
|
||||||
|
|
||||||
|
1. VITE_ADMIN_HANDLEから管理者のhandleを取得する。
|
||||||
|
2. VITE_ATPROTO_PDSから管理者のアカウントのpdsを取得する。
|
||||||
|
3. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
||||||
|
|
||||||
|
```rust
|
||||||
|
match pds {
|
||||||
|
"bsky.social" | "bsky.app" => NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
},
|
||||||
|
"syu.is" => NetworkConfig {
|
||||||
|
pds_api: "https://syu.is".to_string(),
|
||||||
|
plc_api: "https://plc.syu.is".to_string(),
|
||||||
|
bsky_api: "https://bsky.syu.is".to_string(),
|
||||||
|
web_url: "https://web.syu.is".to_string(),
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// Default to Bluesky network for unknown PDS
|
||||||
|
NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 管理者アカウントであるVITE_ADMIN_HANDLEとVITE_ATPROTO_PDSから`ai.syui.log.user`というuserlistを取得する。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${VITE_ADMIN_HANDLE}&collection=ai.syui.log.user"
|
||||||
|
---
|
||||||
|
syui.ai
|
||||||
|
```
|
||||||
|
|
||||||
|
5. ユーザーがわかったら、そのユーザーのpdsを判定する。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -sL "https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo=syui.ai" |jq -r ".didDoc.service.[].serviceEndpoint"
|
||||||
|
---
|
||||||
|
https://shiitake.us-east.host.bsky.network
|
||||||
|
|
||||||
|
curl -sL "https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo=syui.ai" |jq -r ".did"
|
||||||
|
---
|
||||||
|
did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
||||||
|
```
|
||||||
|
|
||||||
|
6. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
||||||
|
|
||||||
|
```rust
|
||||||
|
match pds {
|
||||||
|
"bsky.social" | "bsky.app" => NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
},
|
||||||
|
"syu.is" => NetworkConfig {
|
||||||
|
pds_api: "https://syu.is".to_string(),
|
||||||
|
plc_api: "https://plc.syu.is".to_string(),
|
||||||
|
bsky_api: "https://bsky.syu.is".to_string(),
|
||||||
|
web_url: "https://web.syu.is".to_string(),
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// Default to Bluesky network for unknown PDS
|
||||||
|
NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
7. ユーザーの情報を取得、表示する
|
||||||
|
|
||||||
|
```sh
|
||||||
|
bsky_api=https://public.api.bsky.app
|
||||||
|
user_did=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
||||||
|
curl -sL "$bsky_api/xrpc/app.bsky.actor.getProfile?actor=$user_did"|jq -r .avatar
|
||||||
|
---
|
||||||
|
https://cdn.bsky.app/img/avatar/plain/did:plc:uqzpqmrjnptsxezjx4xuh2mn/bafkreid6kcc5pnn4b3ar7mj6vi3eiawhxgkcrw3edgbqeacyrlnlcoetea@jpeg
|
||||||
|
```
|
||||||
|
|
||||||
|
### AIの情報を表示する
|
||||||
|
|
||||||
|
AIが持つ`ai.syui.log.chat.lang`, `ai.syui.log.chat.comment`を表示します。
|
||||||
|
|
||||||
|
なお、これは通常、`VITE_ADMIN_HANDLE`にputRecordされます。そこから情報を読み込みます。`VITE_AI_HANDLE`はそのrecordの`author`のところに入ります。
|
||||||
|
|
||||||
|
```json
|
||||||
|
"author": {
|
||||||
|
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
|
||||||
|
"avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:4hqjfn7m6n5hno3doamuhgef/bafkreiaxkv624mffw3cfyi67ufxtwuwsy2mjw2ygezsvtd44ycbgkfdo2a@jpeg",
|
||||||
|
"handle": "yui.syui.ai",
|
||||||
|
"displayName": "ai"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
1. VITE_ADMIN_HANDLEから管理者のhandleを取得する。
|
||||||
|
2. VITE_ATPROTO_PDSから管理者のアカウントのpdsを取得する。
|
||||||
|
3. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
||||||
|
|
||||||
|
```rust
|
||||||
|
match pds {
|
||||||
|
"bsky.social" | "bsky.app" => NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
},
|
||||||
|
"syu.is" => NetworkConfig {
|
||||||
|
pds_api: "https://syu.is".to_string(),
|
||||||
|
plc_api: "https://plc.syu.is".to_string(),
|
||||||
|
bsky_api: "https://bsky.syu.is".to_string(),
|
||||||
|
web_url: "https://web.syu.is".to_string(),
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// Default to Bluesky network for unknown PDS
|
||||||
|
NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 管理者アカウントであるVITE_ADMIN_HANDLEとVITE_ATPROTO_PDSから`ai.syui.log.chat.lang`, `ai.syui.log.chat.comment`を取得する。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${VITE_ADMIN_HANDLE}&collection=ai.syui.log.chat.comment"
|
||||||
|
```
|
||||||
|
|
||||||
|
5. AIのprofileを取得する。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.describeRepo?repo=$VITE_AI_HANDLE" |jq -r ".didDoc.service.[].serviceEndpoint"
|
||||||
|
---
|
||||||
|
https://syu.is
|
||||||
|
|
||||||
|
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.describeRepo?repo=$VITE_AI_HANDLE" |jq -r ".did"
|
||||||
|
did:plc:6qyecktefllvenje24fcxnie
|
||||||
|
```
|
||||||
|
|
||||||
|
6. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
||||||
|
|
||||||
|
```rust
|
||||||
|
match pds {
|
||||||
|
"bsky.social" | "bsky.app" => NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
},
|
||||||
|
"syu.is" => NetworkConfig {
|
||||||
|
pds_api: "https://syu.is".to_string(),
|
||||||
|
plc_api: "https://plc.syu.is".to_string(),
|
||||||
|
bsky_api: "https://bsky.syu.is".to_string(),
|
||||||
|
web_url: "https://web.syu.is".to_string(),
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// Default to Bluesky network for unknown PDS
|
||||||
|
NetworkConfig {
|
||||||
|
pds_api: format!("https://{}", pds),
|
||||||
|
plc_api: "https://plc.directory".to_string(),
|
||||||
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
|
web_url: "https://bsky.app".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
7. AIの情報を取得、表示する
|
||||||
|
|
||||||
|
```sh
|
||||||
|
bsky_api=https://bsky.syu.is
|
||||||
|
user_did=did:plc:6qyecktefllvenje24fcxnie
|
||||||
|
curl -sL "$bsky_api/xrpc/app.bsky.actor.getProfile?actor=$user_did"|jq -r .avatar
|
||||||
|
---
|
||||||
|
https://bsky.syu.is/img/avatar/plain/did:plc:6qyecktefllvenje24fcxnie/bafkreiet4pwlnshk7igra5flf2fuxpg2bhvf2apts4rqwcr56hzhgycii4@jpeg
|
||||||
|
```
|
||||||
|
|
||||||
## 中核思想
|
## 中核思想
|
||||||
- **存在子理論**: この世界で最も小さいもの(存在子/ai)の探求
|
- **存在子理論**: この世界で最も小さいもの(存在子/ai)の探求
|
||||||
- **唯一性原則**: 現実の個人の唯一性をすべてのシステムで担保
|
- **唯一性原則**: 現実の個人の唯一性をすべてのシステムで担保
|
||||||
|
33
my-blog/config.toml
Normal file
33
my-blog/config.toml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
[site]
|
||||||
|
title = "syui.ai"
|
||||||
|
description = "a blog powered by ailog"
|
||||||
|
base_url = "https://syui.ai"
|
||||||
|
language = "ja"
|
||||||
|
author = "syui"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
highlight_code = true
|
||||||
|
highlight_theme = "Monokai"
|
||||||
|
minify = false
|
||||||
|
|
||||||
|
[ai]
|
||||||
|
enabled = true
|
||||||
|
auto_translate = false
|
||||||
|
comment_moderation = false
|
||||||
|
ask_ai = true
|
||||||
|
provider = "ollama"
|
||||||
|
model = "qwen3"
|
||||||
|
model_translation = "llama3.2:1b"
|
||||||
|
model_technical = "phi3:mini"
|
||||||
|
host = "http://localhost:11434"
|
||||||
|
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
|
handle = "ai.syui.ai"
|
||||||
|
#num_predict = 200
|
||||||
|
|
||||||
|
[oauth]
|
||||||
|
json = "client-metadata.json"
|
||||||
|
redirect = "oauth/callback"
|
||||||
|
admin = "ai.syui.ai"
|
||||||
|
collection = "ai.syui.log"
|
||||||
|
pds = "syu.is"
|
||||||
|
handle_list = ["syui.syui.ai", "ai.syui.ai", "ai.ai"]
|
157
my-blog/content/posts/2025-06-06-ailog.md
Normal file
157
my-blog/content/posts/2025-06-06-ailog.md
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
---
|
||||||
|
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!");
|
||||||
|
```
|
||||||
|
|
66
my-blog/content/posts/2025-06-14-blog.md
Normal file
66
my-blog/content/posts/2025-06-14-blog.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
---
|
||||||
|
title: "ブログを移行した"
|
||||||
|
slug: "blog"
|
||||||
|
date: 2025-06-14
|
||||||
|
tags: ["blog", "cloudflare", "github"]
|
||||||
|
draft: false
|
||||||
|
---
|
||||||
|
|
||||||
|
ブログを移行しました。過去のブログは[syui.github.io](https://syui.github.io)にありあます。
|
||||||
|
|
||||||
|
1. `gh-pages`から`cf-pages`への移行になります。
|
||||||
|
2. 自作の`ailog`でbuildしています。
|
||||||
|
3. 特徴としては、`atproto`, `AI`との連携です。
|
||||||
|
|
||||||
|
```yml:.github/workflows/cloudflare-pages.yml
|
||||||
|
name: Deploy to Cloudflare Pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Build ailog
|
||||||
|
run: cargo build --release
|
||||||
|
|
||||||
|
- name: Build site with ailog
|
||||||
|
run: |
|
||||||
|
cd my-blog
|
||||||
|
../target/release/ailog build
|
||||||
|
|
||||||
|
- name: List public directory
|
||||||
|
run: |
|
||||||
|
ls -la my-blog/public/
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
|
||||||
|
directory: my-blog/public
|
||||||
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
wranglerVersion: '3'
|
||||||
|
```
|
||||||
|
|
||||||
|
## url
|
||||||
|
|
||||||
|
- [https://syui.pages.dev](https://syui.pages.dev)
|
||||||
|
- [https://syui.github.io](https://syui.github.io)
|
7
my-blog/layouts/_default/index.json
Normal file
7
my-blog/layouts/_default/index.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{{ $dateFormat := default "Mon Jan 2, 2006" (index .Site.Params "date_format") }}
|
||||||
|
{{ $utcFormat := "2006-01-02T15:04:05Z07:00" }}
|
||||||
|
{{- $.Scratch.Add "index" slice -}}
|
||||||
|
{{- range .Site.RegularPages -}}
|
||||||
|
{{- $.Scratch.Add "index" (dict "title" .Title "tags" .Params.tags "description" .Description "categories" .Params.categories "contents" .Plain "href" .Permalink "utc_time" (.Date.Format $utcFormat) "formated_time" (.Date.Format $dateFormat)) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $.Scratch.Get "index" | jsonify -}}
|
20
my-blog/oauth/.env.production
Normal file
20
my-blog/oauth/.env.production
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Handle-based Configuration (DIDs resolved at runtime)
|
||||||
|
VITE_ATPROTO_PDS=syu.is
|
||||||
|
VITE_ADMIN_HANDLE=ai.syui.ai
|
||||||
|
VITE_AI_HANDLE=ai.syui.ai
|
||||||
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||||
|
VITE_ATPROTO_WEB_URL=https://bsky.app
|
||||||
|
VITE_ATPROTO_HANDLE_LIST=["syui.syui.ai", "ai.syui.ai", "ai.ai"]
|
||||||
|
|
||||||
|
# AI Configuration
|
||||||
|
VITE_AI_ENABLED=true
|
||||||
|
VITE_AI_ASK_AI=true
|
||||||
|
VITE_AI_PROVIDER=ollama
|
||||||
|
VITE_AI_MODEL=qwen3
|
||||||
|
VITE_AI_HOST=http://localhost:11434
|
||||||
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
51
my-blog/static/_headers
Normal file
51
my-blog/static/_headers
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
X-Frame-Options: DENY
|
||||||
|
X-Content-Type-Options: nosniff
|
||||||
|
Referrer-Policy: strict-origin-when-cross-origin
|
||||||
|
X-XSS-Protection: 1; mode=block
|
||||||
|
Permissions-Policy: camera=(), microphone=(), geolocation=()
|
||||||
|
|
||||||
|
# OAuth specific headers
|
||||||
|
/oauth/*
|
||||||
|
Access-Control-Allow-Origin: https://bsky.social
|
||||||
|
Access-Control-Allow-Methods: GET, POST, OPTIONS
|
||||||
|
Access-Control-Allow-Headers: Content-Type, Authorization
|
||||||
|
|
||||||
|
# Static assets caching
|
||||||
|
/assets/*
|
||||||
|
Cache-Control: public, max-age=31536000, immutable
|
||||||
|
|
||||||
|
/css/*
|
||||||
|
Content-Type: text/css
|
||||||
|
Cache-Control: no-cache
|
||||||
|
|
||||||
|
/*.js
|
||||||
|
Content-Type: application/javascript
|
||||||
|
Cache-Control: public, max-age=31536000, immutable
|
||||||
|
|
||||||
|
/assets/*.js
|
||||||
|
Content-Type: application/javascript
|
||||||
|
Cache-Control: public, max-age=31536000, immutable
|
||||||
|
|
||||||
|
# Ensure ES6 modules are served correctly
|
||||||
|
/assets/comment-atproto-*.js
|
||||||
|
Content-Type: text/javascript; charset=utf-8
|
||||||
|
Cache-Control: public, max-age=31536000, immutable
|
||||||
|
|
||||||
|
# All JS assets
|
||||||
|
/assets/*-*.js
|
||||||
|
Content-Type: text/javascript; charset=utf-8
|
||||||
|
Cache-Control: public, max-age=31536000, immutable
|
||||||
|
|
||||||
|
# CSS assets
|
||||||
|
/assets/*.css
|
||||||
|
Content-Type: text/css
|
||||||
|
Cache-Control: public, max-age=60
|
||||||
|
|
||||||
|
/posts/*
|
||||||
|
Cache-Control: public, max-age=3600
|
||||||
|
|
||||||
|
# Client metadata for OAuth
|
||||||
|
/client-metadata.json
|
||||||
|
Content-Type: application/json
|
||||||
|
Cache-Control: public, max-age=3600
|
5
my-blog/static/_redirects
Normal file
5
my-blog/static/_redirects
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# OAuth routes
|
||||||
|
/oauth/* /oauth/index.html 200
|
||||||
|
|
||||||
|
# SPA routing support
|
||||||
|
/* /index.html 200
|
BIN
my-blog/static/apple-touch-icon.png
Normal file
BIN
my-blog/static/apple-touch-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
24
my-blog/static/client-metadata.json
Normal file
24
my-blog/static/client-metadata.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"client_id": "https://syui.ai/client-metadata.json",
|
||||||
|
"client_name": "ai.log",
|
||||||
|
"client_uri": "https://syui.ai",
|
||||||
|
"logo_uri": "https://syui.ai/favicon.ico",
|
||||||
|
"tos_uri": "https://syui.ai/terms",
|
||||||
|
"policy_uri": "https://syui.ai/privacy",
|
||||||
|
"redirect_uris": [
|
||||||
|
"https://syui.ai/oauth/callback",
|
||||||
|
"https://syui.ai/"
|
||||||
|
],
|
||||||
|
"response_types": [
|
||||||
|
"code"
|
||||||
|
],
|
||||||
|
"grant_types": [
|
||||||
|
"authorization_code",
|
||||||
|
"refresh_token"
|
||||||
|
],
|
||||||
|
"token_endpoint_auth_method": "none",
|
||||||
|
"scope": "atproto transition:generic",
|
||||||
|
"subject_type": "public",
|
||||||
|
"application_type": "web",
|
||||||
|
"dpop_bound_access_tokens": true
|
||||||
|
}
|
963
my-blog/static/css/style.css
Normal file
963
my-blog/static/css/style.css
Normal file
@@ -0,0 +1,963 @@
|
|||||||
|
/* Theme Colors */
|
||||||
|
:root {
|
||||||
|
--theme-color: #f40;
|
||||||
|
--ai-color: #ff7;
|
||||||
|
--white: #fff;
|
||||||
|
--light-white: #f5f5f5;
|
||||||
|
--dark-white: #d1d9e0;
|
||||||
|
--light-gray: #f6f8fa;
|
||||||
|
--dark-gray: #666;
|
||||||
|
--background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #1f2328;
|
||||||
|
background-color: #ffffff;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Buttons */
|
||||||
|
button {
|
||||||
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Links */
|
||||||
|
a:any-link {
|
||||||
|
color: var(--theme-color);
|
||||||
|
text-decoration-line: unset;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: var(--theme-color);
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override link color for specific buttons */
|
||||||
|
a.view-markdown,
|
||||||
|
a.view-markdown:any-link {
|
||||||
|
color: #ffffff !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout */
|
||||||
|
.container {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: auto 0fr 1fr auto;
|
||||||
|
grid-template-areas:
|
||||||
|
"header"
|
||||||
|
"ask-ai"
|
||||||
|
"main"
|
||||||
|
"footer";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header */
|
||||||
|
.main-header {
|
||||||
|
grid-area: header;
|
||||||
|
background: #ffffff;
|
||||||
|
border-bottom: 1px solid #d1d9e0;
|
||||||
|
padding: 16px 24px;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-content {
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr auto 1fr;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-title {
|
||||||
|
color: var(--theme-color);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
grid-column: 2;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo .likeButton {
|
||||||
|
height: 60px;
|
||||||
|
width: auto;
|
||||||
|
cursor: pointer;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ask AI Button */
|
||||||
|
.ask-ai-btn {
|
||||||
|
background: var(--theme-color);
|
||||||
|
color: var(--white);
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-btn:hover {
|
||||||
|
filter: brightness(1.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ai-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
color: var(--ai-color);
|
||||||
|
display: inline-block;
|
||||||
|
font-family: 'icomoon' !important;
|
||||||
|
speak: none;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-variant: normal;
|
||||||
|
text-transform: none;
|
||||||
|
line-height: 1;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Ask AI Panel */
|
||||||
|
.ask-ai-panel {
|
||||||
|
grid-area: ask-ai;
|
||||||
|
background: #f6f8fa;
|
||||||
|
border-bottom: 1px solid #d1d9e0;
|
||||||
|
padding: 24px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-panel[style*="block"] {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container:has(.ask-ai-panel[style*="block"]) {
|
||||||
|
grid-template-rows: auto auto 1fr auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-content {
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-form {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-form input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-check {
|
||||||
|
background: #f6f8fa;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 16px;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Main Content */
|
||||||
|
.main-content {
|
||||||
|
grid-area: main;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
/* padding: 24px; */
|
||||||
|
padding-top: 80px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1000px) {
|
||||||
|
.main-content {
|
||||||
|
/* padding: 20px; */
|
||||||
|
padding: 0px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Timeline */
|
||||||
|
.timeline-container {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-header h2 {
|
||||||
|
color: #1f2328;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-feed {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-post {
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
transition: box-shadow 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-post:hover {
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title a {
|
||||||
|
color: var(--theme-color);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title a:hover {
|
||||||
|
color: var(--theme-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-date {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-excerpt {
|
||||||
|
color: #656d76;
|
||||||
|
margin: 16px 0;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-more {
|
||||||
|
color: var(--theme-color);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-more:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-markdown, .view-translation {
|
||||||
|
color: #656d76;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-markdown {
|
||||||
|
background: var(--theme-color) !important;
|
||||||
|
color: #ffffff !important;
|
||||||
|
border: 1px solid var(--theme-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-markdown:hover {
|
||||||
|
filter: brightness(1.1);
|
||||||
|
color: #ffffff !important;
|
||||||
|
background: var(--theme-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-translation:hover {
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-lang {
|
||||||
|
background: #f6f8fa;
|
||||||
|
color: #656d76;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Article */
|
||||||
|
.article-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 240px;
|
||||||
|
gap: 40px;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
article.article-content {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-meta {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-date {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-lang {
|
||||||
|
background: #f6f8fa;
|
||||||
|
color: #656d76;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
color: var(--theme-color);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:hover {
|
||||||
|
background: #f6f8fa;
|
||||||
|
border-color: var(--theme-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-btn {
|
||||||
|
background: var(--dark-white);
|
||||||
|
color: var(--white);
|
||||||
|
border-color: var(--white);
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-btn:link,
|
||||||
|
.markdown-btn:visited {
|
||||||
|
color: var(--white) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-btn:hover {
|
||||||
|
filter: brightness(0.9);
|
||||||
|
color: var(--theme-color) !important;
|
||||||
|
border-color: var(--white);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sidebar styles */
|
||||||
|
.article-sidebar {
|
||||||
|
position: sticky;
|
||||||
|
top: 100px;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
background: #f6f8fa;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h3 {
|
||||||
|
color: #1f2328;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hierarchy indentation for TOC */
|
||||||
|
.toc-item.toc-h1 .toc-link {
|
||||||
|
padding-left: 0;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.toc-h2 .toc-link {
|
||||||
|
padding-left: 0;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.toc-h3 .toc-link {
|
||||||
|
padding-left: 16px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.toc-h4 .toc-link {
|
||||||
|
padding-left: 32px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.toc-h5 .toc-link {
|
||||||
|
padding-left: 48px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.toc-h6 .toc-link {
|
||||||
|
padding-left: 64px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 11px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-link {
|
||||||
|
color: #656d76;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.4;
|
||||||
|
display: block;
|
||||||
|
padding: 4px 0;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-link:hover {
|
||||||
|
color: var(--theme-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-title {
|
||||||
|
color: #1f2328;
|
||||||
|
font-size: 32px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body {
|
||||||
|
color: #1f2328;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body h1, .article-body h2, .article-body h3 {
|
||||||
|
color: #1f2328;
|
||||||
|
margin-top: 24px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body p {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body ol, .article-body ul {
|
||||||
|
margin: 16px 0;
|
||||||
|
padding-left: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body li {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body ol li {
|
||||||
|
list-style-type: decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body ul li {
|
||||||
|
list-style-type: disc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre {
|
||||||
|
background: #1B1D1E !important;
|
||||||
|
border: 1px solid #3E3D32;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 16px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* File name display for code blocks - top bar style */
|
||||||
|
.article-body pre[data-filename]::before {
|
||||||
|
content: attr(data-filename);
|
||||||
|
display: block;
|
||||||
|
background: #2D2D30;
|
||||||
|
color: #AE81FF;
|
||||||
|
padding: 8px 16px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
|
||||||
|
border-bottom: 1px solid #3E3D32;
|
||||||
|
margin: 0;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre code {
|
||||||
|
display: block;
|
||||||
|
background: none !important;
|
||||||
|
padding: 30px 16px;
|
||||||
|
color: #F8F8F2 !important;
|
||||||
|
font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
|
||||||
|
overflow-x: auto;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust padding when filename is present */
|
||||||
|
.article-body pre[data-filename] code {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Inline code (not in pre blocks) */
|
||||||
|
.article-body code {
|
||||||
|
background: var(--light-white);
|
||||||
|
color: var(--dark-gray);
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Molokai syntax highlighting */
|
||||||
|
.article-body pre code .hljs-keyword { color: #F92672; }
|
||||||
|
.article-body pre code .hljs-string { color: #E6DB74; }
|
||||||
|
.article-body pre code .hljs-comment { color: #88846F; font-style: italic; }
|
||||||
|
.article-body pre code .hljs-number { color: #AE81FF; }
|
||||||
|
.article-body pre code .hljs-variable { color: #FD971F; }
|
||||||
|
.article-body pre code .hljs-function { color: #A6E22E; }
|
||||||
|
.article-body pre code .hljs-tag { color: #F92672; }
|
||||||
|
.article-body pre code .hljs-attr { color: #A6E22E; }
|
||||||
|
.article-body pre code .hljs-value { color: #E6DB74; }
|
||||||
|
|
||||||
|
/* Fix inline span colors in code blocks */
|
||||||
|
.article-body pre code span[style*="color:#8fa1b3"] { color: #AE81FF !important; } /* $ prompt */
|
||||||
|
.article-body pre code span[style*="color:#c0c5ce"] { color: #F8F8F2 !important; } /* commands */
|
||||||
|
.article-body pre code span[style*="color:#75715E"] { color: #88846F !important; } /* real comments */
|
||||||
|
|
||||||
|
/* Shell/Bash specific fixes */
|
||||||
|
.article-body pre code span[style*="color:#65737e"] {
|
||||||
|
color: #F8F8F2 !important; /* Default to white for variables and code */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Comments in shell scripts - lines that contain # followed by text */
|
||||||
|
.article-body pre code span[style*="color:#65737e"]:has-text("#") {
|
||||||
|
color: #88846F !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Alternative approach - check content */
|
||||||
|
.article-body pre code {
|
||||||
|
/* Reset all gray colored text to white by default */
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre code span[style*="color:#65737e"] {
|
||||||
|
/* Check if the content starts with # */
|
||||||
|
color: #F8F8F2 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override for actual comments - this is a workaround */
|
||||||
|
.article-body pre code span[style*="color:#65737e"]:first-child:before {
|
||||||
|
content: attr(data-comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detect comments by position and content pattern */
|
||||||
|
.article-body pre code span[style*="color:#65737e"] {
|
||||||
|
color: #F8F8F2 !important; /* Environment variables = white */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only style as comment if the line actually starts with # */
|
||||||
|
.article-body pre code > span:first-child[style*="color:#65737e"] {
|
||||||
|
color: #88846F !important; /* Real comments = gray */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
|
.main-footer {
|
||||||
|
grid-area: footer;
|
||||||
|
background: var(--light-white);
|
||||||
|
border-top: 1px solid #d1d9e0;
|
||||||
|
padding: 32px 24px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-social {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 24px;
|
||||||
|
margin: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-social a {
|
||||||
|
color: var(--dark-gray) !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-social a:hover {
|
||||||
|
color: var(--theme-color) !important;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-footer p {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 14px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Chat Messages */
|
||||||
|
.chat-message.comment-style {
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-message.ai-message.comment-style {
|
||||||
|
border-left: 4px solid var(--ai-color);
|
||||||
|
background: #faf8ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-header .avatar {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #f6f8fa;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 20px;
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.display-name {
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1f2328;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.handle {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timestamp {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content {
|
||||||
|
color: #1f2328;
|
||||||
|
line-height: 1.5;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-avatar {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loading Animation */
|
||||||
|
.ai-loading-simple {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
background: linear-gradient(90deg, #f8f9fa 0%, #e9ecef 100%);
|
||||||
|
border-radius: 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #495057;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
animation: slideIn 0.3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-10px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Comment System Styles */
|
||||||
|
.comment-section {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
margin-top: 48px;
|
||||||
|
padding-top: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-container {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-section h3 {
|
||||||
|
color: #1f2328;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OAuth Comment System - Hide on homepage by default, show on post pages */
|
||||||
|
.timeline-container .comment-section {
|
||||||
|
display: block; /* Show on homepage */
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-container .comment-section .comments-list > :nth-child(n+6) {
|
||||||
|
display: none; /* Hide comments after the 5th one */
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-container .comment-section,
|
||||||
|
.article-content + .comment-section {
|
||||||
|
display: block; /* Show all comments on post pages */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 1000px) {
|
||||||
|
.article-container {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 24px;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1000px) {
|
||||||
|
.main-header {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-content {
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 0 20px;
|
||||||
|
grid-template-columns: auto 1fr auto;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OAuth app mobile fixes */
|
||||||
|
.comment-item {
|
||||||
|
padding: 0px !important;
|
||||||
|
margin: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comments-list {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-section {
|
||||||
|
max-width: 100% !important;
|
||||||
|
padding: 0px !important;
|
||||||
|
margin: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-container {
|
||||||
|
max-width: 100% !important;
|
||||||
|
padding: 0px !important;
|
||||||
|
margin: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content {
|
||||||
|
padding: 10px !important;
|
||||||
|
word-wrap: break-word !important;
|
||||||
|
overflow-wrap: break-word !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-header {
|
||||||
|
padding: 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix comment-meta URI overflow */
|
||||||
|
.comment-meta {
|
||||||
|
word-break: break-all !important;
|
||||||
|
overflow-wrap: break-word !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide site title text on mobile */
|
||||||
|
.site-title {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Left align logo on mobile */
|
||||||
|
.logo {
|
||||||
|
grid-column: 1;
|
||||||
|
justify-self: left;
|
||||||
|
padding: 5px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reduce logo size on mobile */
|
||||||
|
.logo .likeButton {
|
||||||
|
width: 40pt;
|
||||||
|
height: 40pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Position AI button on the right */
|
||||||
|
.header-actions {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ask AI button mobile style - icon only */
|
||||||
|
.ask-ai-btn {
|
||||||
|
padding: 8px;
|
||||||
|
min-width: 40px;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0;
|
||||||
|
font-size: 0; /* Hide all text content */
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-btn .ai-icon {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-panel {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Article content mobile optimization */
|
||||||
|
.article-body {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre {
|
||||||
|
margin: 16px 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre code {
|
||||||
|
padding: 20px 12px;
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile filename display */
|
||||||
|
.article-body pre[data-filename]::before {
|
||||||
|
padding: 6px 12px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body pre[data-filename] code {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-body code {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-ai-form {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-container {
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-post {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-title {
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 30px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-header .avatar {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Center content on mobile */
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
342
my-blog/static/css/svg-animation-package.css
Normal file
342
my-blog/static/css/svg-animation-package.css
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
/* SVG Animation Package - Dependency-free standalone package
|
||||||
|
* Based on svg-animation-particle-circle.css
|
||||||
|
* Theme color integration with CSS variables
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Theme-based color variables for particles */
|
||||||
|
:root {
|
||||||
|
--particle-color-1: #f40; /* theme-color base */
|
||||||
|
--particle-color-2: #f50; /* theme-color +0.1 brightness */
|
||||||
|
--particle-color-3: #f60; /* theme-color +0.2 brightness */
|
||||||
|
--particle-color-4: #f70; /* theme-color +0.3 brightness */
|
||||||
|
--particle-color-5: #f80; /* theme-color +0.4 brightness */
|
||||||
|
--explosion-color: #f30; /* theme-color -0.1 brightness */
|
||||||
|
--syui-color: #f40; /* main theme color */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Core SVG button setup */
|
||||||
|
.likeButton {
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove debug animation and restore hover functionality */
|
||||||
|
|
||||||
|
.likeButton .border {
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Explosion circle - initially hidden */
|
||||||
|
.likeButton .explosion {
|
||||||
|
transform-origin: center center;
|
||||||
|
transform: scale(1);
|
||||||
|
stroke: var(--explosion-color);
|
||||||
|
fill: none;
|
||||||
|
opacity: 0;
|
||||||
|
stroke-width: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Particle layer - initially hidden */
|
||||||
|
.likeButton .particleLayer {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0); /* Ensure particles start hidden */
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer circle {
|
||||||
|
opacity: 0;
|
||||||
|
transform-origin: center center; /* Fixed from 250px 250px */
|
||||||
|
transform: scale(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Syui logo - main animation target */
|
||||||
|
.likeButton .syui {
|
||||||
|
fill: var(--syui-color);
|
||||||
|
transform: scale(1);
|
||||||
|
transform-origin: center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hover trigger - replaces jQuery */
|
||||||
|
.likeButton:hover .explosion {
|
||||||
|
animation: explosionAnime 800ms forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer {
|
||||||
|
animation: particleLayerAnime 800ms forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .syui,
|
||||||
|
.likeButton:hover path.syui {
|
||||||
|
animation: syuiDeluxeAnime 400ms forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Individual particle animations */
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(1) {
|
||||||
|
animation: particleAnimate1 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(2) {
|
||||||
|
animation: particleAnimate2 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(3) {
|
||||||
|
animation: particleAnimate3 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(4) {
|
||||||
|
animation: particleAnimate4 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(5) {
|
||||||
|
animation: particleAnimate5 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(6) {
|
||||||
|
animation: particleAnimate6 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(7) {
|
||||||
|
animation: particleAnimate7 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(8) {
|
||||||
|
animation: particleAnimate8 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(9) {
|
||||||
|
animation: particleAnimate9 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(10) {
|
||||||
|
animation: particleAnimate10 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(11) {
|
||||||
|
animation: particleAnimate11 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(12) {
|
||||||
|
animation: particleAnimate12 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(13) {
|
||||||
|
animation: particleAnimate13 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer circle:nth-child(14) {
|
||||||
|
animation: particleAnimate14 800ms;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keyframe animations */
|
||||||
|
@keyframes explosionAnime {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.01);
|
||||||
|
}
|
||||||
|
1% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(0.01);
|
||||||
|
}
|
||||||
|
5% {
|
||||||
|
stroke-width: 200;
|
||||||
|
}
|
||||||
|
20% {
|
||||||
|
stroke-width: 300;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
stroke: var(--particle-color-3);
|
||||||
|
transform: scale(1.1);
|
||||||
|
stroke-width: 1;
|
||||||
|
}
|
||||||
|
50.1% {
|
||||||
|
stroke-width: 0;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
stroke: var(--particle-color-3);
|
||||||
|
transform: scale(1.1);
|
||||||
|
stroke-width: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleLayerAnime {
|
||||||
|
0% {
|
||||||
|
transform: translate(0, 0);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
30% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
31% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
transform: translate(0, 0);
|
||||||
|
}
|
||||||
|
70% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translate(0, -20px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Syui Deluxe Animation - Based on 2019 blog post */
|
||||||
|
@keyframes syuiDeluxeAnime {
|
||||||
|
0% {
|
||||||
|
fill: var(--syui-color);
|
||||||
|
transform: scale(1) translate(0%, 0%);
|
||||||
|
}
|
||||||
|
40% {
|
||||||
|
fill: color-mix(in srgb, var(--syui-color) 40%, transparent);
|
||||||
|
transform: scale(1, 0.9) translate(-9%, 9%);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
fill: color-mix(in srgb, var(--syui-color) 70%, transparent);
|
||||||
|
transform: scale(1, 0.9) translate(-7%, 7%);
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
transform: scale(1) translate(-7%, 7%);
|
||||||
|
}
|
||||||
|
70% {
|
||||||
|
transform: scale(1.04) translate(-5%, 5%);
|
||||||
|
}
|
||||||
|
80% {
|
||||||
|
fill: color-mix(in srgb, var(--syui-color) 60%, transparent);
|
||||||
|
transform: scale(1.04) translate(-5%, 5%);
|
||||||
|
}
|
||||||
|
90% {
|
||||||
|
fill: var(--particle-color-5); /* 爆発の閃光 */
|
||||||
|
transform: scale(1) translate(0%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
fill: var(--syui-color);
|
||||||
|
transform: scale(1, 1) translate(0%, 0%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Individual particle animations */
|
||||||
|
@keyframes particleAnimate1 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-16px, -59px); }
|
||||||
|
90% { transform: translate(-16px, -59px); }
|
||||||
|
100% { opacity: 1; transform: translate(-16px, -59px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate2 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(41px, 43px); }
|
||||||
|
90% { transform: translate(41px, 43px); }
|
||||||
|
100% { opacity: 1; transform: translate(41px, 43px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate3 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(50px, -48px); }
|
||||||
|
90% { transform: translate(50px, -48px); }
|
||||||
|
100% { opacity: 1; transform: translate(50px, -48px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate4 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-39px, 36px); }
|
||||||
|
90% { transform: translate(-39px, 36px); }
|
||||||
|
100% { opacity: 1; transform: translate(-39px, 36px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate5 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-39px, 32px); }
|
||||||
|
90% { transform: translate(-39px, 32px); }
|
||||||
|
100% { opacity: 1; transform: translate(-39px, 32px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate6 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(48px, 6px); }
|
||||||
|
90% { transform: translate(48px, 6px); }
|
||||||
|
100% { opacity: 1; transform: translate(48px, 6px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate7 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-69px, -36px); }
|
||||||
|
90% { transform: translate(-69px, -36px); }
|
||||||
|
100% { opacity: 1; transform: translate(-69px, -36px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate8 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-12px, -52px); }
|
||||||
|
90% { transform: translate(-12px, -52px); }
|
||||||
|
100% { opacity: 1; transform: translate(-12px, -52px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate9 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-43px, -21px); }
|
||||||
|
90% { transform: translate(-43px, -21px); }
|
||||||
|
100% { opacity: 1; transform: translate(-43px, -21px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate10 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-10px, 47px); }
|
||||||
|
90% { transform: translate(-10px, 47px); }
|
||||||
|
100% { opacity: 1; transform: translate(-10px, 47px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate11 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(66px, -9px); }
|
||||||
|
90% { transform: translate(66px, -9px); }
|
||||||
|
100% { opacity: 1; transform: translate(66px, -9px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate12 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(40px, -45px); }
|
||||||
|
90% { transform: translate(40px, -45px); }
|
||||||
|
100% { opacity: 1; transform: translate(40px, -45px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate13 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(29px, 24px); }
|
||||||
|
90% { transform: translate(29px, 24px); }
|
||||||
|
100% { opacity: 1; transform: translate(29px, 24px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes particleAnimate14 {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
30% { opacity: 1; transform: translate(0, 0); }
|
||||||
|
80% { transform: translate(-10px, 50px); }
|
||||||
|
90% { transform: translate(-10px, 50px); }
|
||||||
|
100% { opacity: 1; transform: translate(-10px, 50px); }
|
||||||
|
}
|
BIN
my-blog/static/favicon.ico
Normal file
BIN
my-blog/static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
BIN
my-blog/static/favicon.png
Normal file
BIN
my-blog/static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
22
my-blog/static/favicon.svg
Normal file
22
my-blog/static/favicon.svg
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<svg width="77pt" height="77pt" viewBox="0 0 512 512" class="likeButton" >
|
||||||
|
<circle class="explosion" r="150" cx="250" cy="250"></circle>
|
||||||
|
<g class="particleLayer">
|
||||||
|
<circle fill="#ef454aba" cx="130" cy="126.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454acc" cx="411" cy="313.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="279" cy="86.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="155" cy="390.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="89" cy="292.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="414" cy="282.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="115" cy="149.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="250" cy="80.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="78" cy="261.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="182" cy="402.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="401.5" cy="166" r="13"/>
|
||||||
|
<circle fill="#ef454aba" cx="379" cy="141.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="327" cy="397.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="296" cy="392.5" r="10.5"/>
|
||||||
|
</g>
|
||||||
|
<g transform="translate(0,512) scale(0.1,-0.1)" fill="#000000" class="icon_syui">
|
||||||
|
<path class="syui" d="M3660 4460 c-11 -11 -33 -47 -48 -80 l-29 -60 -12 38 c-27 88 -58 92 -98 11 -35 -70 -73 -159 -73 -169 0 -6 -5 -10 -10 -10 -6 0 -15 -10 -21 -22 -33 -73 -52 -92 -47 -48 2 26 -1 35 -14 38 -16 3 -168 -121 -168 -138 0 -5 -13 -16 -28 -24 -24 -13 -35 -12 -87 0 -221 55 -231 56 -480 56 -219 1 -247 -1 -320 -22 -44 -12 -96 -26 -115 -30 -57 -13 -122 -39 -200 -82 -8 -4 -31 -14 -50 -23 -41 -17 -34 -13 -146 -90 -87 -59 -292 -252 -351 -330 -63 -83 -143 -209 -143 -225 0 -10 -7 -23 -15 -30 -8 -7 -15 -17 -15 -22 0 -5 -13 -37 -28 -71 -16 -34 -36 -93 -45 -132 -9 -38 -24 -104 -34 -145 -13 -60 -17 -121 -17 -300 1 -224 1 -225 36 -365 24 -94 53 -175 87 -247 28 -58 51 -108 51 -112 0 -3 13 -24 28 -48 42 -63 46 -79 22 -85 -11 -3 -20 -9 -20 -14 0 -5 -4 -9 -10 -9 -5 0 -22 -11 -37 -25 -16 -13 -75 -59 -133 -100 -58 -42 -113 -82 -123 -90 -9 -8 -22 -15 -27 -15 -6 0 -10 -6 -10 -13 0 -8 -11 -20 -25 -27 -34 -18 -34 -54 0 -48 14 3 25 2 25 -1 0 -3 -43 -31 -95 -61 -52 -30 -95 -58 -95 -62 0 -5 -5 -8 -11 -8 -19 0 -84 -33 -92 -47 -4 -7 -15 -13 -22 -13 -14 0 -17 -4 -19 -32 -1 -8 15 -15 37 -18 l38 -5 -47 -48 c-56 -59 -54 -81 9 -75 30 3 45 0 54 -11 9 -13 16 -14 43 -4 29 11 30 10 18 -5 -7 -9 -19 -23 -25 -30 -7 -7 -13 -20 -13 -29 0 -12 8 -14 38 -9 20 4 57 8 82 9 25 2 54 8 66 15 18 10 23 8 32 -13 17 -38 86 -35 152 6 27 17 50 34 50 38 0 16 62 30 85 19 33 -15 72 -2 89 30 8 15 31 43 51 62 35 34 38 35 118 35 77 0 85 2 126 33 24 17 52 32 61 32 9 0 42 18 73 40 30 22 61 40 69 40 21 0 88 -26 100 -38 7 -7 17 -12 24 -12 7 0 35 -11 62 -25 66 -33 263 -84 387 -101 189 -25 372 -12 574 41 106 27 130 37 261 97 41 20 80 37 85 39 6 2 51 31 100 64 166 111 405 372 489 534 10 20 22 43 27 51 5 8 12 22 15 30 3 8 17 40 31 70 54 115 95 313 108 520 13 200 -43 480 -134 672 -28 58 -51 108 -51 112 0 3 -13 24 -29 48 -15 24 -34 60 -40 80 -19 57 3 142 50 193 10 11 22 49 28 85 6 36 16 67 21 68 18 6 31 53 25 83 -4 18 -17 33 -36 41 -16 7 -29 15 -29 18 1 10 38 50 47 50 5 0 20 11 33 25 18 19 22 31 17 61 -3 20 -14 45 -23 55 -16 18 -16 20 6 44 15 16 21 32 18 49 -3 15 1 34 8 43 32 43 7 73 -46 55 l-30 -11 0 85 c0 74 -2 84 -18 84 -21 0 -53 -33 -103 -104 l-34 -48 -5 74 c-7 102 -35 133 -80 88z m-870 -740 c36 -7 75 -14 88 -16 21 -4 23 -9 16 -37 -3 -18 -14 -43 -24 -57 -10 -14 -20 -35 -24 -46 -4 -12 -16 -32 -27 -45 -12 -13 -37 -49 -56 -79 -20 -30 -52 -73 -72 -96 -53 -60 -114 -133 -156 -189 -21 -27 -44 -54 -52 -58 -7 -4 -13 -14 -13 -22 0 -7 -18 -33 -40 -57 -22 -23 -40 -46 -40 -50 0 -5 -19 -21 -42 -38 -47 -35 -85 -38 -188 -15 -115 25 -173 20 -264 -23 -45 -22 -106 -46 -136 -56 -48 -15 -77 -25 -140 -50 -70 -28 -100 -77 -51 -84 14 -2 34 -10 45 -17 12 -7 53 -16 91 -20 90 -9 131 -22 178 -57 20 -16 52 -35 70 -43 18 -7 40 -22 49 -32 16 -18 15 -22 -24 -88 -23 -39 -47 -74 -53 -80 -7 -5 -23 -26 -36 -45 -26 -39 -92 -113 -207 -232 -4 -4 -37 -36 -73 -71 l-66 -64 -20 41 c-58 119 -105 240 -115 301 -40 244 -35 409 20 595 8 30 21 66 28 80 7 14 24 54 38 89 15 35 35 75 46 89 11 13 20 31 20 38 0 8 3 14 8 14 4 0 16 16 27 36 24 45 221 245 278 281 23 15 44 30 47 33 20 20 138 78 250 123 61 24 167 50 250 61 60 7 302 -1 370 -14z m837 -661 c52 -101 102 -279 106 -379 2 -42 0 -45 -28 -51 -16 -4 -101 -7 -187 -8 -166 -1 -229 10 -271 49 -19 19 -19 19 14 49 22 21 44 31 65 31 41 0 84 34 84 66 0 30 12 55 56 112 19 25 37 65 44 95 11 51 53 111 74 104 6 -2 25 -32 43 -68z m-662 -810 c17 -10 40 -24 53 -30 12 -7 22 -16 22 -20 0 -4 17 -13 38 -19 20 -7 44 -18 52 -24 8 -7 33 -21 55 -31 22 -11 42 -23 45 -26 11 -14 109 -49 164 -58 62 -11 101 -7 126 14 15 14 38 18 78 16 39 -2 26 -41 -49 -146 -78 -109 -85 -118 -186 -219 -61 -61 -239 -189 -281 -203 -17 -5 -73 -29 -104 -44 -187 -92 -605 -103 -791 -21 -42 19 -47 24 -37 41 5 11 28 32 51 48 22 15 51 38 64 51 13 12 28 22 33 22 17 0 242 233 242 250 0 6 5 10 10 10 6 0 10 6 10 14 0 25 50 55 100 62 59 8 56 6 115 83 50 66 74 117 75 162 0 14 7 40 16 57 18 38 52 41 99 11z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 4.8 KiB |
31
my-blog/static/index.json
Normal file
31
my-blog/static/index.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"categories": [],
|
||||||
|
"contents": "ブログを移行しました。過去のブログはsyui.github.ioにありあます。 gh-pagesからcf-pagesへの移行になります。 自作のailogでbuildしています。 特徴としては、atproto, AIとの連携です。 name: Deploy to Cloudflare Pages on: push: branches: - main workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest permissions: contents: read deployments: write steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Rust uses: actions-rs/toolchain@v1 with: toolchain: stable - name: Build ailog run: cargo build --release - name: Build site with ailog run: | cd my-blog ../target/release/ailog build - name: List public directory run: | ls -la my-blog/public/ - name: Deploy to Cloudflare Pages uses: cloudflare/pages-action@v1 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} directory: my-blog/public gitHubToken: ${{ secrets.GITHUB_TOKEN }} wranglerVersion: '3' url https://syui.pages.dev https://syui.github.io",
|
||||||
|
"description": "ブログを移行しました。過去のブログはsyui.github.ioにありあます。 \n\ngh-pagesからcf-pagesへの移行になります。\n自作のailogでbuildしています。\n特徴としては、atproto, AIとの連携です。\n\nname: Deploy to Cloudflare Pages\n\non:\n push:\n branches:\n - main\n workfl...",
|
||||||
|
"formated_time": "Sat Jun 14, 2025",
|
||||||
|
"href": "https://syui.ai/posts/2025-06-14-blog.html",
|
||||||
|
"tags": [
|
||||||
|
"blog",
|
||||||
|
"cloudflare",
|
||||||
|
"github"
|
||||||
|
],
|
||||||
|
"title": "ブログを移行した",
|
||||||
|
"utc_time": "2025-06-14T00:00:00Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"categories": [],
|
||||||
|
"contents": "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!");",
|
||||||
|
"description": "rustで静的サイトジェネレータを作りました。ailogといいます。hugoからの移行になります。 \nailogは、最初にatproto-comment-system(oauth)とask-AIという機能をつけました。 \nquick start\n$ git clone https://git.syui.ai/ai/log\n$ cd log\n$ cargo build\n$ ./target/debu...",
|
||||||
|
"formated_time": "Thu Jun 12, 2025",
|
||||||
|
"href": "https://syui.ai/posts/2025-06-06-ailog.html",
|
||||||
|
"tags": [
|
||||||
|
"blog",
|
||||||
|
"rust",
|
||||||
|
"mcp",
|
||||||
|
"atp"
|
||||||
|
],
|
||||||
|
"title": "静的サイトジェネレータを作った",
|
||||||
|
"utc_time": "2025-06-12T00:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
295
my-blog/static/js/ask-ai.js
Normal file
295
my-blog/static/js/ask-ai.js
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
/**
|
||||||
|
* Ask AI functionality - Based on original working implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Global variables for AI functionality
|
||||||
|
let aiProfileData = null;
|
||||||
|
|
||||||
|
// Original functions from working implementation
|
||||||
|
function toggleAskAI() {
|
||||||
|
const panel = document.getElementById('askAiPanel');
|
||||||
|
const isVisible = panel.style.display !== 'none';
|
||||||
|
panel.style.display = isVisible ? 'none' : 'block';
|
||||||
|
|
||||||
|
if (!isVisible) {
|
||||||
|
checkAuthenticationStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAuthenticationStatus() {
|
||||||
|
const userSections = document.querySelectorAll('.user-section');
|
||||||
|
const isAuthenticated = userSections.length > 0;
|
||||||
|
|
||||||
|
if (isAuthenticated) {
|
||||||
|
// User is authenticated - show Ask AI UI
|
||||||
|
document.getElementById('authCheck').style.display = 'none';
|
||||||
|
document.getElementById('chatForm').style.display = 'block';
|
||||||
|
document.getElementById('chatHistory').style.display = 'block';
|
||||||
|
|
||||||
|
// Show initial greeting if chat history is empty
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
if (chatHistory.children.length === 0) {
|
||||||
|
showInitialGreeting();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus on input
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('aiQuestion').focus();
|
||||||
|
}, 50);
|
||||||
|
} else {
|
||||||
|
// User not authenticated - show auth message
|
||||||
|
document.getElementById('authCheck').style.display = 'block';
|
||||||
|
document.getElementById('chatForm').style.display = 'none';
|
||||||
|
document.getElementById('chatHistory').style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function askQuestion() {
|
||||||
|
const question = document.getElementById('aiQuestion').value;
|
||||||
|
if (!question.trim()) return;
|
||||||
|
|
||||||
|
const askButton = document.getElementById('askButton');
|
||||||
|
askButton.disabled = true;
|
||||||
|
askButton.textContent = 'Posting...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Add user message to chat
|
||||||
|
addUserMessage(question);
|
||||||
|
|
||||||
|
// Clear input
|
||||||
|
document.getElementById('aiQuestion').value = '';
|
||||||
|
|
||||||
|
// Show loading
|
||||||
|
showLoadingMessage();
|
||||||
|
|
||||||
|
// Post question via OAuth app
|
||||||
|
window.dispatchEvent(new CustomEvent('postAIQuestion', {
|
||||||
|
detail: { question: question }
|
||||||
|
}));
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to ask question:', error);
|
||||||
|
showErrorMessage('Sorry, I encountered an error. Please try again.');
|
||||||
|
} finally {
|
||||||
|
askButton.disabled = false;
|
||||||
|
askButton.textContent = 'Ask';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addUserMessage(question) {
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
const userSection = document.querySelector('.user-section');
|
||||||
|
|
||||||
|
let userAvatar = '👤';
|
||||||
|
let userDisplay = 'You';
|
||||||
|
let userHandle = 'user';
|
||||||
|
|
||||||
|
if (userSection) {
|
||||||
|
const avatarImg = userSection.querySelector('.user-avatar');
|
||||||
|
const displayName = userSection.querySelector('.user-display-name');
|
||||||
|
const handle = userSection.querySelector('.user-handle');
|
||||||
|
|
||||||
|
if (avatarImg && avatarImg.src) {
|
||||||
|
userAvatar = `<img src="${avatarImg.src}" alt="${displayName?.textContent || 'User'}" class="profile-avatar">`;
|
||||||
|
}
|
||||||
|
if (displayName?.textContent) {
|
||||||
|
userDisplay = displayName.textContent;
|
||||||
|
}
|
||||||
|
if (handle?.textContent) {
|
||||||
|
userHandle = handle.textContent.replace('@', '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const questionDiv = document.createElement('div');
|
||||||
|
questionDiv.className = 'chat-message user-message comment-style';
|
||||||
|
questionDiv.innerHTML = `
|
||||||
|
<div class="message-header">
|
||||||
|
<div class="avatar">${userAvatar}</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<div class="display-name">${userDisplay}</div>
|
||||||
|
<div class="handle">@${userHandle}</div>
|
||||||
|
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="message-content">${question}</div>
|
||||||
|
`;
|
||||||
|
chatHistory.appendChild(questionDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoadingMessage() {
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
const loadingDiv = document.createElement('div');
|
||||||
|
loadingDiv.className = 'ai-loading-simple';
|
||||||
|
loadingDiv.innerHTML = `
|
||||||
|
<i class="fas fa-robot"></i>
|
||||||
|
<span>考えています</span>
|
||||||
|
<i class="fas fa-spinner fa-spin"></i>
|
||||||
|
`;
|
||||||
|
chatHistory.appendChild(loadingDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showErrorMessage(message) {
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
removeLoadingMessage();
|
||||||
|
|
||||||
|
const errorDiv = document.createElement('div');
|
||||||
|
errorDiv.className = 'chat-message error-message comment-style';
|
||||||
|
errorDiv.innerHTML = `
|
||||||
|
<div class="message-header">
|
||||||
|
<div class="avatar">⚠️</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<div class="display-name">System</div>
|
||||||
|
<div class="handle">@system</div>
|
||||||
|
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="message-content">${message}</div>
|
||||||
|
`;
|
||||||
|
chatHistory.appendChild(errorDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeLoadingMessage() {
|
||||||
|
const loadingMsg = document.querySelector('.ai-loading-simple');
|
||||||
|
if (loadingMsg) {
|
||||||
|
loadingMsg.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInitialGreeting() {
|
||||||
|
if (!aiProfileData) return;
|
||||||
|
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
const greetingDiv = document.createElement('div');
|
||||||
|
greetingDiv.className = 'chat-message ai-message comment-style initial-greeting';
|
||||||
|
|
||||||
|
const avatarElement = aiProfileData.avatar
|
||||||
|
? `<img src="${aiProfileData.avatar}" alt="${aiProfileData.displayName}" class="profile-avatar">`
|
||||||
|
: '🤖';
|
||||||
|
|
||||||
|
greetingDiv.innerHTML = `
|
||||||
|
<div class="message-header">
|
||||||
|
<div class="avatar">${avatarElement}</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<div class="display-name">${aiProfileData.displayName}</div>
|
||||||
|
<div class="handle">@${aiProfileData.handle}</div>
|
||||||
|
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="message-content">
|
||||||
|
Hello! I'm an AI assistant trained on this blog's content. I can answer questions about the articles, provide insights, and help you understand the topics discussed here. What would you like to know?
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
chatHistory.appendChild(greetingDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAskAIButton() {
|
||||||
|
const button = document.getElementById('askAiButton');
|
||||||
|
if (!button) return;
|
||||||
|
|
||||||
|
// Only update text, never modify the icon
|
||||||
|
if (aiProfileData && aiProfileData.displayName) {
|
||||||
|
const textNode = button.childNodes[2] || button.lastChild;
|
||||||
|
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
|
||||||
|
textNode.textContent = aiProfileData.displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAIResponse(responseData) {
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
removeLoadingMessage();
|
||||||
|
|
||||||
|
const aiProfile = responseData.aiProfile;
|
||||||
|
if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) {
|
||||||
|
console.error('AI profile data is missing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamp = new Date(responseData.timestamp || Date.now());
|
||||||
|
const avatarElement = aiProfile.avatar
|
||||||
|
? `<img src="${aiProfile.avatar}" alt="${aiProfile.displayName}" class="profile-avatar">`
|
||||||
|
: '🤖';
|
||||||
|
|
||||||
|
const answerDiv = document.createElement('div');
|
||||||
|
answerDiv.className = 'chat-message ai-message comment-style';
|
||||||
|
answerDiv.innerHTML = `
|
||||||
|
<div class="message-header">
|
||||||
|
<div class="avatar">${avatarElement}</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<div class="display-name">${aiProfile.displayName}</div>
|
||||||
|
<div class="handle">@${aiProfile.handle}</div>
|
||||||
|
<div class="timestamp">${timestamp.toLocaleString()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="message-content">${responseData.answer}</div>
|
||||||
|
`;
|
||||||
|
chatHistory.appendChild(answerDiv);
|
||||||
|
|
||||||
|
// Limit chat history
|
||||||
|
limitChatHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
function limitChatHistory() {
|
||||||
|
const chatHistory = document.getElementById('chatHistory');
|
||||||
|
if (chatHistory.children.length > 10) {
|
||||||
|
chatHistory.removeChild(chatHistory.children[0]);
|
||||||
|
if (chatHistory.children.length > 0) {
|
||||||
|
chatHistory.removeChild(chatHistory.children[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event listeners setup
|
||||||
|
function setupAskAIEventListeners() {
|
||||||
|
// Listen for AI profile updates from OAuth app
|
||||||
|
window.addEventListener('aiProfileLoaded', function(event) {
|
||||||
|
aiProfileData = event.detail;
|
||||||
|
console.log('AI profile loaded:', aiProfileData);
|
||||||
|
updateAskAIButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Listen for AI responses
|
||||||
|
window.addEventListener('aiResponseReceived', function(event) {
|
||||||
|
handleAIResponse(event.detail);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track IME composition state
|
||||||
|
let isComposing = false;
|
||||||
|
const aiQuestionInput = document.getElementById('aiQuestion');
|
||||||
|
|
||||||
|
if (aiQuestionInput) {
|
||||||
|
aiQuestionInput.addEventListener('compositionstart', function() {
|
||||||
|
isComposing = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
aiQuestionInput.addEventListener('compositionend', function() {
|
||||||
|
isComposing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard shortcuts
|
||||||
|
document.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
const panel = document.getElementById('askAiPanel');
|
||||||
|
if (panel) {
|
||||||
|
panel.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enter key to send message (only when not composing Japanese input)
|
||||||
|
if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey && !isComposing) {
|
||||||
|
e.preventDefault();
|
||||||
|
askQuestion();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Ask AI when DOM is loaded
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
setupAskAIEventListeners();
|
||||||
|
console.log('Ask AI initialized successfully');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Global functions for onclick handlers
|
||||||
|
window.toggleAskAI = toggleAskAI;
|
||||||
|
window.askQuestion = askQuestion;
|
94
my-blog/static/js/theme.js
Normal file
94
my-blog/static/js/theme.js
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Theme and visual effects - Pure CSS animations, no jQuery
|
||||||
|
*/
|
||||||
|
class Theme {
|
||||||
|
constructor() {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.setupParticleColors();
|
||||||
|
this.setupLogoAnimations();
|
||||||
|
}
|
||||||
|
|
||||||
|
setupParticleColors() {
|
||||||
|
// Dynamic particle colors based on theme
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.textContent = `
|
||||||
|
/* Dynamic particle colors based on theme */
|
||||||
|
.likeButton .particleLayer circle:nth-child(1),
|
||||||
|
.likeButton .particleLayer circle:nth-child(2) {
|
||||||
|
fill: var(--particle-color-1) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer circle:nth-child(3),
|
||||||
|
.likeButton .particleLayer circle:nth-child(4) {
|
||||||
|
fill: var(--particle-color-2) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer circle:nth-child(5),
|
||||||
|
.likeButton .particleLayer circle:nth-child(6),
|
||||||
|
.likeButton .particleLayer circle:nth-child(7) {
|
||||||
|
fill: var(--particle-color-3) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer circle:nth-child(8),
|
||||||
|
.likeButton .particleLayer circle:nth-child(9),
|
||||||
|
.likeButton .particleLayer circle:nth-child(10) {
|
||||||
|
fill: var(--particle-color-4) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer circle:nth-child(11),
|
||||||
|
.likeButton .particleLayer circle:nth-child(12),
|
||||||
|
.likeButton .particleLayer circle:nth-child(13),
|
||||||
|
.likeButton .particleLayer circle:nth-child(14) {
|
||||||
|
fill: var(--particle-color-5) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset initial animations but allow hover */
|
||||||
|
.likeButton .syui {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .particleLayer {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton .explosion {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enable hover animations from package */
|
||||||
|
.likeButton:hover .syui,
|
||||||
|
.likeButton:hover path.syui {
|
||||||
|
animation: syuiDeluxeAnime 400ms forwards !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .particleLayer {
|
||||||
|
animation: particleLayerAnime 800ms forwards !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.likeButton:hover .explosion {
|
||||||
|
animation: explosionAnime 800ms forwards !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Logo positioning */
|
||||||
|
.logo .likeButton {
|
||||||
|
background: transparent !important;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
document.head.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLogoAnimations() {
|
||||||
|
// Pure CSS animations are handled by the svg-animation-package.css
|
||||||
|
// This method is reserved for any future JavaScript-based enhancements
|
||||||
|
console.log('Logo animations initialized (CSS-based)');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize theme when DOM is loaded
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
new Theme();
|
||||||
|
});
|
165
my-blog/static/pkg/font-awesome/LICENSE.txt
Normal file
165
my-blog/static/pkg/font-awesome/LICENSE.txt
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
Fonticons, Inc. (https://fontawesome.com)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Font Awesome Free License
|
||||||
|
|
||||||
|
Font Awesome Free is free, open source, and GPL friendly. You can use it for
|
||||||
|
commercial projects, open source projects, or really almost whatever you want.
|
||||||
|
Full Font Awesome Free license: https://fontawesome.com/license/free.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
|
||||||
|
|
||||||
|
The Font Awesome Free download is licensed under a Creative Commons
|
||||||
|
Attribution 4.0 International License and applies to all icons packaged
|
||||||
|
as SVG and JS file types.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Fonts: SIL OFL 1.1 License
|
||||||
|
|
||||||
|
In the Font Awesome Free download, the SIL OFL license applies to all icons
|
||||||
|
packaged as web and desktop font files.
|
||||||
|
|
||||||
|
Copyright (c) 2024 Fonticons, Inc. (https://fontawesome.com)
|
||||||
|
with Reserved Font Name: "Font Awesome".
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
SIL OPEN FONT LICENSE
|
||||||
|
Version 1.1 - 26 February 2007
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting — in part or in whole — any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Code: MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
In the Font Awesome Free download, the MIT license applies to all non-font and
|
||||||
|
non-icon files.
|
||||||
|
|
||||||
|
Copyright 2024 Fonticons, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
and to permit persons to whom the Software is furnished to do so, subject to the
|
||||||
|
following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Attribution
|
||||||
|
|
||||||
|
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
|
||||||
|
Awesome Free files already contain embedded comments with sufficient
|
||||||
|
attribution, so you shouldn't need to do anything additional when using these
|
||||||
|
files normally.
|
||||||
|
|
||||||
|
We've kept attribution comments terse, so we ask that you do not actively work
|
||||||
|
to remove them from files, especially code. They're a great way for folks to
|
||||||
|
learn about Font Awesome.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Brand Icons
|
||||||
|
|
||||||
|
All brand icons are trademarks of their respective owners. The use of these
|
||||||
|
trademarks does not indicate endorsement of the trademark holder by Font
|
||||||
|
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
|
||||||
|
to represent the company, product, or service to which they refer.**
|
9
my-blog/static/pkg/font-awesome/css/all.min.css
vendored
Normal file
9
my-blog/static/pkg/font-awesome/css/all.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
my-blog/static/pkg/font-awesome/css/brands.min.css
vendored
Normal file
6
my-blog/static/pkg/font-awesome/css/brands.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
9
my-blog/static/pkg/font-awesome/css/fontawesome.min.css
vendored
Normal file
9
my-blog/static/pkg/font-awesome/css/fontawesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
my-blog/static/pkg/font-awesome/css/regular.min.css
vendored
Normal file
6
my-blog/static/pkg/font-awesome/css/regular.min.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/*!
|
||||||
|
* Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com
|
||||||
|
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
||||||
|
* Copyright 2024 Fonticons, Inc.
|
||||||
|
*/
|
||||||
|
:host,:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-regular:normal 400 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:400;font-display:block;src:url(../webfonts/fa-regular-400.woff2) format("woff2"),url(../webfonts/fa-regular-400.ttf) format("truetype")}.fa-regular,.far{font-weight:400}
|
6
my-blog/static/pkg/font-awesome/css/solid.min.css
vendored
Normal file
6
my-blog/static/pkg/font-awesome/css/solid.min.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/*!
|
||||||
|
* Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com
|
||||||
|
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
||||||
|
* Copyright 2024 Fonticons, Inc.
|
||||||
|
*/
|
||||||
|
:host,:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-solid:normal 900 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:900;font-display:block;src:url(../webfonts/fa-solid-900.woff2) format("woff2"),url(../webfonts/fa-solid-900.ttf) format("truetype")}.fa-solid,.fas{font-weight:900}
|
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-brands-400.ttf
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-brands-400.ttf
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-brands-400.woff2
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-brands-400.woff2
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-regular-400.ttf
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-regular-400.ttf
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-regular-400.woff2
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-regular-400.woff2
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-solid-900.ttf
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-solid-900.ttf
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-solid-900.woff2
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-solid-900.woff2
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-v4compatibility.ttf
Normal file
BIN
my-blog/static/pkg/font-awesome/webfonts/fa-v4compatibility.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.eot
Normal file
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.eot
Normal file
Binary file not shown.
34
my-blog/static/pkg/icomoon/fonts/icomoon.svg
Normal file
34
my-blog/static/pkg/icomoon/fonts/icomoon.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 58 KiB |
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.ttf
Normal file
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.ttf
Normal file
Binary file not shown.
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.woff
Normal file
BIN
my-blog/static/pkg/icomoon/fonts/icomoon.woff
Normal file
Binary file not shown.
99
my-blog/static/pkg/icomoon/style.css
Normal file
99
my-blog/static/pkg/icomoon/style.css
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'icomoon';
|
||||||
|
src: url('fonts/icomoon.eot?mxezzh');
|
||||||
|
src: url('fonts/icomoon.eot?mxezzh#iefix') format('embedded-opentype'),
|
||||||
|
url('fonts/icomoon.ttf?mxezzh') format('truetype'),
|
||||||
|
url('fonts/icomoon.woff?mxezzh') format('woff'),
|
||||||
|
url('fonts/icomoon.svg?mxezzh#icomoon') format('svg');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
[class^="icon-"], [class*=" icon-"] {
|
||||||
|
/* use !important to prevent issues with browser extensions that change fonts */
|
||||||
|
font-family: 'icomoon' !important;
|
||||||
|
speak: never;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
font-variant: normal;
|
||||||
|
text-transform: none;
|
||||||
|
line-height: 1;
|
||||||
|
|
||||||
|
/* Better Font Rendering =========== */
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-git:before {
|
||||||
|
content: "\e901";
|
||||||
|
}
|
||||||
|
.icon-cube:before {
|
||||||
|
content: "\e900";
|
||||||
|
}
|
||||||
|
.icon-game:before {
|
||||||
|
content: "\e9d5";
|
||||||
|
}
|
||||||
|
.icon-card:before {
|
||||||
|
content: "\e9d6";
|
||||||
|
}
|
||||||
|
.icon-book:before {
|
||||||
|
content: "\e9d7";
|
||||||
|
}
|
||||||
|
.icon-git1:before {
|
||||||
|
content: "\e9d3";
|
||||||
|
}
|
||||||
|
.icon-moji_a:before {
|
||||||
|
content: "\e9c3";
|
||||||
|
}
|
||||||
|
.icon-archlinux:before {
|
||||||
|
content: "\e9c4";
|
||||||
|
}
|
||||||
|
.icon-archlinuxjp:before {
|
||||||
|
content: "\e9c5";
|
||||||
|
}
|
||||||
|
.icon-syui:before {
|
||||||
|
content: "\e9c6";
|
||||||
|
}
|
||||||
|
.icon-phoenix-power:before {
|
||||||
|
content: "\e9c7";
|
||||||
|
}
|
||||||
|
.icon-phoenix-world:before {
|
||||||
|
content: "\e9c8";
|
||||||
|
}
|
||||||
|
.icon-power:before {
|
||||||
|
content: "\e9c9";
|
||||||
|
}
|
||||||
|
.icon-phoenix:before {
|
||||||
|
content: "\e9ca";
|
||||||
|
}
|
||||||
|
.icon-honeycomb:before {
|
||||||
|
content: "\e9cb";
|
||||||
|
}
|
||||||
|
.icon-ai:before {
|
||||||
|
content: "\e9cc";
|
||||||
|
}
|
||||||
|
.icon-robot:before {
|
||||||
|
content: "\e9cd";
|
||||||
|
}
|
||||||
|
.icon-sandar:before {
|
||||||
|
content: "\e9ce";
|
||||||
|
}
|
||||||
|
.icon-moon:before {
|
||||||
|
content: "\e9cf";
|
||||||
|
}
|
||||||
|
.icon-home:before {
|
||||||
|
content: "\e9d0";
|
||||||
|
}
|
||||||
|
.icon-cloud:before {
|
||||||
|
content: "\e9d1";
|
||||||
|
}
|
||||||
|
.icon-api:before {
|
||||||
|
content: "\e9d2";
|
||||||
|
}
|
||||||
|
.icon-aibadge:before {
|
||||||
|
content: "\ebf8";
|
||||||
|
}
|
||||||
|
.icon-aiterm:before {
|
||||||
|
content: "\ebf7";
|
||||||
|
}
|
24
my-blog/static/syui.svg
Normal file
24
my-blog/static/syui.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<svg width="77pt" height="77pt" viewBox="0 0 512 512" class="likeButton" >
|
||||||
|
<circle class="explosion" r="150" cx="250" cy="250"></circle>
|
||||||
|
<g class="particleLayer">
|
||||||
|
<circle fill="#ef454aba" cx="130" cy="126.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454acc" cx="411" cy="313.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="279" cy="86.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="155" cy="390.5" r="12.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="89" cy="292.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="414" cy="282.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="115" cy="149.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="250" cy="80.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="78" cy="261.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="182" cy="402.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="401.5" cy="166" r="13"/>
|
||||||
|
<circle fill="#ef454aba" cx="379" cy="141.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454a91" cx="327" cy="397.5" r="10.5"/>
|
||||||
|
<circle fill="#ef454aba" cx="296" cy="392.5" r="10.5"/>
|
||||||
|
</g>
|
||||||
|
<g transform="translate(0,512) scale(0.1,-0.1)" fill="#000000" class="icon_syui">
|
||||||
|
|
||||||
|
<path class="syui" d="M3660 4460 c-11 -11 -33 -47 -48 -80 l-29 -60 -12 38 c-27 88 -58 92 -98 11 -35 -70 -73 -159 -73 -169 0 -6 -5 -10 -10 -10 -6 0 -15 -10 -21 -22 -33 -73 -52 -92 -47 -48 2 26 -1 35 -14 38 -16 3 -168 -121 -168 -138 0 -5 -13 -16 -28 -24 -24 -13 -35 -12 -87 0 -221 55 -231 56 -480 56 -219 1 -247 -1 -320 -22 -44 -12 -96 -26 -115 -30 -57 -13 -122 -39 -200 -82 -8 -4 -31 -14 -50 -23 -41 -17 -34 -13 -146 -90 -87 -59 -292 -252 -351 -330 -63 -83 -143 -209 -143 -225 0 -10 -7 -23 -15 -30 -8 -7 -15 -17 -15 -22 0 -5 -13 -37 -28 -71 -16 -34 -36 -93 -45 -132 -9 -38 -24 -104 -34 -145 -13 -60 -17 -121 -17 -300 1 -224 1 -225 36 -365 24 -94 53 -175 87 -247 28 -58 51 -108 51 -112 0 -3 13 -24 28 -48 42 -63 46 -79 22 -85 -11 -3 -20 -9 -20 -14 0 -5 -4 -9 -10 -9 -5 0 -22 -11 -37 -25 -16 -13 -75 -59 -133 -100 -58 -42 -113 -82 -123 -90 -9 -8 -22 -15 -27 -15 -6 0 -10 -6 -10 -13 0 -8 -11 -20 -25 -27 -34 -18 -34 -54 0 -48 14 3 25 2 25 -1 0 -3 -43 -31 -95 -61 -52 -30 -95 -58 -95 -62 0 -5 -5 -8 -11 -8 -19 0 -84 -33 -92 -47 -4 -7 -15 -13 -22 -13 -14 0 -17 -4 -19 -32 -1 -8 15 -15 37 -18 l38 -5 -47 -48 c-56 -59 -54 -81 9 -75 30 3 45 0 54 -11 9 -13 16 -14 43 -4 29 11 30 10 18 -5 -7 -9 -19 -23 -25 -30 -7 -7 -13 -20 -13 -29 0 -12 8 -14 38 -9 20 4 57 8 82 9 25 2 54 8 66 15 18 10 23 8 32 -13 17 -38 86 -35 152 6 27 17 50 34 50 38 0 16 62 30 85 19 33 -15 72 -2 89 30 8 15 31 43 51 62 35 34 38 35 118 35 77 0 85 2 126 33 24 17 52 32 61 32 9 0 42 18 73 40 30 22 61 40 69 40 21 0 88 -26 100 -38 7 -7 17 -12 24 -12 7 0 35 -11 62 -25 66 -33 263 -84 387 -101 189 -25 372 -12 574 41 106 27 130 37 261 97 41 20 80 37 85 39 6 2 51 31 100 64 166 111 405 372 489 534 10 20 22 43 27 51 5 8 12 22 15 30 3 8 17 40 31 70 54 115 95 313 108 520 13 200 -43 480 -134 672 -28 58 -51 108 -51 112 0 3 -13 24 -29 48 -15 24 -34 60 -40 80 -19 57 3 142 50 193 10 11 22 49 28 85 6 36 16 67 21 68 18 6 31 53 25 83 -4 18 -17 33 -36 41 -16 7 -29 15 -29 18 1 10 38 50 47 50 5 0 20 11 33 25 18 19 22 31 17 61 -3 20 -14 45 -23 55 -16 18 -16 20 6 44 15 16 21 32 18 49 -3 15 1 34 8 43 32 43 7 73 -46 55 l-30 -11 0 85 c0 74 -2 84 -18 84 -21 0 -53 -33 -103 -104 l-34 -48 -5 74 c-7 102 -35 133 -80 88z m-870 -740 c36 -7 75 -14 88 -16 21 -4 23 -9 16 -37 -3 -18 -14 -43 -24 -57 -10 -14 -20 -35 -24 -46 -4 -12 -16 -32 -27 -45 -12 -13 -37 -49 -56 -79 -20 -30 -52 -73 -72 -96 -53 -60 -114 -133 -156 -189 -21 -27 -44 -54 -52 -58 -7 -4 -13 -14 -13 -22 0 -7 -18 -33 -40 -57 -22 -23 -40 -46 -40 -50 0 -5 -19 -21 -42 -38 -47 -35 -85 -38 -188 -15 -115 25 -173 20 -264 -23 -45 -22 -106 -46 -136 -56 -48 -15 -77 -25 -140 -50 -70 -28 -100 -77 -51 -84 14 -2 34 -10 45 -17 12 -7 53 -16 91 -20 90 -9 131 -22 178 -57 20 -16 52 -35 70 -43 18 -7 40 -22 49 -32 16 -18 15 -22 -24 -88 -23 -39 -47 -74 -53 -80 -7 -5 -23 -26 -36 -45 -26 -39 -92 -113 -207 -232 -4 -4 -37 -36 -73 -71 l-66 -64 -20 41 c-58 119 -105 240 -115 301 -40 244 -35 409 20 595 8 30 21 66 28 80 7 14 24 54 38 89 15 35 35 75 46 89 11 13 20 31 20 38 0 8 3 14 8 14 4 0 16 16 27 36 24 45 221 245 278 281 23 15 44 30 47 33 20 20 138 78 250 123 61 24 167 50 250 61 60 7 302 -1 370 -14z m837 -661 c52 -101 102 -279 106 -379 2 -42 0 -45 -28 -51 -16 -4 -101 -7 -187 -8 -166 -1 -229 10 -271 49 -19 19 -19 19 14 49 22 21 44 31 65 31 41 0 84 34 84 66 0 30 12 55 56 112 19 25 37 65 44 95 11 51 53 111 74 104 6 -2 25 -32 43 -68z m-662 -810 c17 -10 40 -24 53 -30 12 -7 22 -16 22 -20 0 -4 17 -13 38 -19 20 -7 44 -18 52 -24 8 -7 33 -21 55 -31 22 -11 42 -23 45 -26 11 -14 109 -49 164 -58 62 -11 101 -7 126 14 15 14 38 18 78 16 39 -2 26 -41 -49 -146 -78 -109 -85 -118 -186 -219 -61 -61 -239 -189 -281 -203 -17 -5 -73 -29 -104 -44 -187 -92 -605 -103 -791 -21 -42 19 -47 24 -37 41 5 11 28 32 51 48 22 15 51 38 64 51 13 12 28 22 33 22 17 0 242 233 242 250 0 6 5 10 10 10 6 0 10 6 10 14 0 25 50 55 100 62 59 8 56 6 115 83 50 66 74 117 75 162 0 14 7 40 16 57 18 38 52 41 99 11z"/>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
</svg>
|
After Width: | Height: | Size: 4.8 KiB |
97
my-blog/templates/base.html
Normal file
97
my-blog/templates/base.html
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="{{ config.language }}">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}{{ config.title }}{% endblock %}</title>
|
||||||
|
|
||||||
|
<!-- Favicon -->
|
||||||
|
<link rel="icon" href="/favicon.ico" />
|
||||||
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||||
|
|
||||||
|
<!-- Stylesheets -->
|
||||||
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
<link rel="stylesheet" href="/css/svg-animation-package.css">
|
||||||
|
<link rel="stylesheet" href="/pkg/icomoon/style.css">
|
||||||
|
<link rel="stylesheet" href="/pkg/font-awesome/css/all.min.css">
|
||||||
|
|
||||||
|
{% block head %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header class="main-header">
|
||||||
|
<div class="header-content">
|
||||||
|
<h1><a href="/" class="site-title">{{ config.title }}</a></h1>
|
||||||
|
<div class="logo">
|
||||||
|
<a href="/">
|
||||||
|
<svg width="77pt" height="77pt" viewBox="0 0 512 512" class="likeButton">
|
||||||
|
<circle class="explosion" r="150" cx="250" cy="250"></circle>
|
||||||
|
<g class="particleLayer">
|
||||||
|
<circle fill="#8CE8C3" cx="130" cy="126.5" r="12.5"></circle>
|
||||||
|
<circle fill="#8CE8C3" cx="411" cy="313.5" r="12.5"></circle>
|
||||||
|
<circle fill="#91D2FA" cx="279" cy="86.5" r="12.5"></circle>
|
||||||
|
<circle fill="#91D2FA" cx="155" cy="390.5" r="12.5"></circle>
|
||||||
|
<circle fill="#CC8EF5" cx="89" cy="292.5" r="10.5"></circle>
|
||||||
|
<circle fill="#9BDFBA" cx="414" cy="282.5" r="10.5"></circle>
|
||||||
|
<circle fill="#9BDFBA" cx="115" cy="149.5" r="10.5"></circle>
|
||||||
|
<circle fill="#9FC7FA" cx="250" cy="80.5" r="10.5"></circle>
|
||||||
|
<circle fill="#9FC7FA" cx="78" cy="261.5" r="10.5"></circle>
|
||||||
|
<circle fill="#96D8E9" cx="182" cy="402.5" r="10.5"></circle>
|
||||||
|
<circle fill="#CC8EF5" cx="401.5" cy="166" r="13"></circle>
|
||||||
|
<circle fill="#DB92D0" cx="379" cy="141.5" r="10.5"></circle>
|
||||||
|
<circle fill="#DB92D0" cx="327" cy="397.5" r="10.5"></circle>
|
||||||
|
<circle fill="#DD99B8" cx="296" cy="392.5" r="10.5"></circle>
|
||||||
|
</g>
|
||||||
|
<g transform="translate(0,512) scale(0.1,-0.1)" fill="#000000" class="icon_syui">
|
||||||
|
<path class="syui" d="M3660 4460 c-11 -11 -33 -47 -48 -80 l-29 -60 -12 38 c-27 88 -58 92 -98 11 -35 -70 -73 -159 -73 -169 0 -6 -5 -10 -10 -10 -6 0 -15 -10 -21 -22 -33 -73 -52 -92 -47 -48 2 26 -1 35 -14 38 -16 3 -168 -121 -168 -138 0 -5 -13 -16 -28 -24 -24 -13 -35 -12 -87 0 -221 55 -231 56 -480 56 -219 1 -247 -1 -320 -22 -44 -12 -96 -26 -115 -30 -57 -13 -122 -39 -200 -82 -8 -4 -31 -14 -50 -23 -41 -17 -34 -13 -146 -90 -87 -59 -292 -252 -351 -330 -63 -83 -143 -209 -143 -225 0 -10 -7 -23 -15 -30 -8 -7 -15 -17 -15 -22 0 -5 -13 -37 -28 -71 -16 -34 -36 -93 -45 -132 -9 -38 -24 -104 -34 -145 -13 -60 -17 -121 -17 -300 1 -224 1 -225 36 -365 24 -94 53 -175 87 -247 28 -58 51 -108 51 -112 0 -3 13 -24 28 -48 42 -63 46 -79 22 -85 -11 -3 -20 -9 -20 -14 0 -5 -4 -9 -10 -9 -5 0 -22 -11 -37 -25 -16 -13 -75 -59 -133 -100 -58 -42 -113 -82 -123 -90 -9 -8 -22 -15 -27 -15 -6 0 -10 -6 -10 -13 0 -8 -11 -20 -25 -27 -34 -18 -34 -54 0 -48 14 3 25 2 25 -1 0 -3 -43 -31 -95 -61 -52 -30 -95 -58 -95 -62 0 -5 -5 -8 -11 -8 -19 0 -84 -33 -92 -47 -4 -7 -15 -13 -22 -13 -14 0 -17 -4 -19 -32 -1 -8 15 -15 37 -18 l38 -5 -47 -48 c-56 -59 -54 -81 9 -75 30 3 45 0 54 -11 9 -13 16 -14 43 -4 29 11 30 10 18 -5 -7 -9 -19 -23 -25 -30 -7 -7 -13 -20 -13 -29 0 -12 8 -14 38 -9 20 4 57 8 82 9 25 2 54 8 66 15 18 10 23 8 32 -13 17 -38 86 -35 152 6 27 17 50 34 50 38 0 16 62 30 85 19 33 -15 72 -2 89 30 8 15 31 43 51 62 35 34 38 35 118 35 77 0 85 2 126 33 24 17 52 32 61 32 9 0 42 18 73 40 30 22 61 40 69 40 21 0 88 -26 100 -38 7 -7 17 -12 24 -12 7 0 35 -11 62 -25 66 -33 263 -84 387 -101 189 -25 372 -12 574 41 106 27 130 37 261 97 41 20 80 37 85 39 6 2 51 31 100 64 166 111 405 372 489 534 10 20 22 43 27 51 5 8 12 22 15 30 3 8 17 40 31 70 54 115 95 313 108 520 13 200 -43 480 -134 672 -28 58 -51 108 -51 112 0 3 -13 24 -29 48 -15 24 -34 60 -40 80 -19 57 3 142 50 193 10 11 22 49 28 85 6 36 16 67 21 68 18 6 31 53 25 83 -4 18 -17 33 -36 41 -16 7 -29 15 -29 18 1 10 38 50 47 50 5 0 20 11 33 25 18 19 22 31 17 61 -3 20 -14 45 -23 55 -16 18 -16 20 6 44 15 16 21 32 18 49 -3 15 1 34 8 43 32 43 7 73 -46 55 l-30 -11 0 85 c0 74 -2 84 -18 84 -21 0 -53 -33 -103 -104 l-34 -48 -5 74 c-7 102 -35 133 -80 88z m-870 -740 c36 -7 75 -14 88 -16 21 -4 23 -9 16 -37 -3 -18 -14 -43 -24 -57 -10 -14 -20 -35 -24 -46 -4 -12 -16 -32 -27 -45 -12 -13 -37 -49 -56 -79 -20 -30 -52 -73 -72 -96 -53 -60 -114 -133 -156 -189 -21 -27 -44 -54 -52 -58 -7 -4 -13 -14 -13 -22 0 -7 -18 -33 -40 -57 -22 -23 -40 -46 -40 -50 0 -5 -19 -21 -42 -38 -47 -35 -85 -38 -188 -15 -115 25 -173 20 -264 -23 -45 -22 -106 -46 -136 -56 -48 -15 -77 -25 -140 -50 -70 -28 -100 -77 -51 -84 14 -2 34 -10 45 -17 12 -7 53 -16 91 -20 90 -9 131 -22 178 -57 20 -16 52 -35 70 -43 18 -7 40 -22 49 -32 16 -18 15 -22 -24 -88 -23 -39 -47 -74 -53 -80 -7 -5 -23 -26 -36 -45 -26 -39 -92 -113 -207 -232 -4 -4 -37 -36 -73 -71 l-66 -64 -20 41 c-58 119 -105 240 -115 301 -40 244 -35 409 20 595 8 30 21 66 28 80 7 14 24 54 38 89 15 35 35 75 46 89 11 13 20 31 20 38 0 8 3 14 8 14 4 0 16 16 27 36 24 45 221 245 278 281 23 15 44 30 47 33 20 20 138 78 250 123 61 24 167 50 250 61 60 7 302 -1 370 -14z m837 -661 c52 -101 102 -279 106 -379 2 -42 0 -45 -28 -51 -16 -4 -101 -7 -187 -8 -166 -1 -229 10 -271 49 -19 19 -19 19 14 49 22 21 44 31 65 31 41 0 84 34 84 66 0 30 12 55 56 112 19 25 37 65 44 95 11 51 53 111 74 104 6 -2 25 -32 43 -68z m-662 -810 c17 -10 40 -24 53 -30 12 -7 22 -16 22 -20 0 -4 17 -13 38 -19 20 -7 44 -18 52 -24 8 -7 33 -21 55 -31 22 -11 42 -23 45 -26 11 -14 109 -49 164 -58 62 -11 101 -7 126 14 15 14 38 18 78 16 39 -2 26 -41 -49 -146 -78 -109 -85 -118 -186 -219 -61 -61 -239 -189 -281 -203 -17 -5 -73 -29 -104 -44 -187 -92 -605 -103 -791 -21 -42 19 -47 24 -37 41 5 11 28 32 51 48 22 15 51 38 64 51 13 12 28 22 33 22 17 0 242 233 242 250 0 6 5 10 10 10 6 0 10 6 10 14 0 25 50 55 100 62 59 8 56 6 115 83 50 66 74 117 75 162 0 14 7 40 16 57 18 38 52 41 99 11z"></path>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<button class="ask-ai-btn" onclick="toggleAskAI()" id="askAiButton">
|
||||||
|
<span class="ai-icon icon-ai"></span>
|
||||||
|
ai
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Ask AI Panel -->
|
||||||
|
<div class="ask-ai-panel" id="askAiPanel" style="display: none;">
|
||||||
|
<div class="ask-ai-content">
|
||||||
|
<div id="authCheck" class="auth-check">
|
||||||
|
<p>🔒 Please login with ATProto to use Ask AI feature</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chatForm" class="ask-ai-form" style="display: none;">
|
||||||
|
<input type="text" id="aiQuestion" placeholder="What would you like to know?" />
|
||||||
|
<button onclick="askQuestion()" id="askButton">Ask</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chatHistory" class="chat-history" style="display: none;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main class="main-content">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
|
||||||
|
{% block sidebar %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="main-footer">
|
||||||
|
<div class="footer-social">
|
||||||
|
<a href="https://syu.is/syui" target="_blank"><i class="fab fa-bluesky"></i></a>
|
||||||
|
<a href="https://git.syui.ai/ai" target="_blank"><span class="icon-ai"></span></a>
|
||||||
|
<a href="https://git.syui.ai/syui" target="_blank"><span class="icon-git"></span></a>
|
||||||
|
</div>
|
||||||
|
<p>© {{ config.author }}</p>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="/js/ask-ai.js"></script>
|
||||||
|
<script src="/js/theme.js"></script>
|
||||||
|
|
||||||
|
{% include "oauth-assets.html" %}
|
||||||
|
</body>
|
||||||
|
</html>
|
39
my-blog/templates/index.html
Normal file
39
my-blog/templates/index.html
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="timeline-container">
|
||||||
|
|
||||||
|
<div class="timeline-feed">
|
||||||
|
{% for post in posts %}
|
||||||
|
<article class="timeline-post">
|
||||||
|
<div class="post-header">
|
||||||
|
<div class="post-meta">
|
||||||
|
<time class="post-date">{{ post.date }}</time>
|
||||||
|
{% if post.language %}
|
||||||
|
<span class="post-lang">{{ post.language }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="post-content">
|
||||||
|
<h3 class="post-title">
|
||||||
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- OAuth Comment System -->
|
||||||
|
<section class="comment-section">
|
||||||
|
<div id="comment-atproto"></div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% if posts|length == 0 %}
|
||||||
|
<div class="empty-state">
|
||||||
|
<p>No posts yet. Start writing!</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
71
my-blog/templates/partials/oauth-widget.html
Normal file
71
my-blog/templates/partials/oauth-widget.html
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<!-- OAuth authentication widget for ailog -->
|
||||||
|
<div id="oauth-widget">
|
||||||
|
<div id="status" class="status">
|
||||||
|
Login with your Bluesky account
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Login form -->
|
||||||
|
<div id="login-form">
|
||||||
|
<input type="text" id="handle-input" placeholder="Enter your handle (e.g., user.bsky.social)" style="width: 300px; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px;">
|
||||||
|
<br>
|
||||||
|
<button id="login-btn">🦋 Login with Bluesky</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Authenticated state -->
|
||||||
|
<div id="authenticated-state" style="display: none;">
|
||||||
|
<div id="user-info"></div>
|
||||||
|
<button id="logout-btn">Logout</button>
|
||||||
|
<button id="test-profile-btn">Get Profile</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="console-log" class="log"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/oauth-widget-simple.js"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.status {
|
||||||
|
margin: 20px 0;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
.user-info {
|
||||||
|
background: #e8f5e8;
|
||||||
|
border: 1px solid #4caf50;
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
background: #ffeaea;
|
||||||
|
border: 1px solid #f44336;
|
||||||
|
color: #d32f2f;
|
||||||
|
}
|
||||||
|
#oauth-widget button {
|
||||||
|
background: #1185fe;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
#oauth-widget button:hover {
|
||||||
|
background: #0d6efd;
|
||||||
|
}
|
||||||
|
#oauth-widget button:disabled {
|
||||||
|
background: #6c757d;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
.log {
|
||||||
|
text-align: left;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 20px 0;
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
</style>
|
373
my-blog/templates/post-complex.html
Normal file
373
my-blog/templates/post-complex.html
Normal file
@@ -0,0 +1,373 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ post.title }} - {{ config.title }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="article-container">
|
||||||
|
<article class="article-content">
|
||||||
|
<header class="article-header">
|
||||||
|
<h1 class="article-title">{{ post.title }}</h1>
|
||||||
|
<div class="article-meta">
|
||||||
|
<time class="article-date">{{ post.date }}</time>
|
||||||
|
{% if post.language %}
|
||||||
|
<span class="article-lang">{{ post.language }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="article-actions">
|
||||||
|
{% if post.markdown_url %}
|
||||||
|
<a href="{{ post.markdown_url }}" class="action-btn markdown-btn" title="View Markdown">
|
||||||
|
.md
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if post.translation_url %}
|
||||||
|
<a href="{{ post.translation_url }}" class="action-btn translation-btn" title="View Translation">
|
||||||
|
🌐 {% if post.language == 'ja' %}English{% else %}日本語{% endif %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="article-body">
|
||||||
|
{{ post.content | safe }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Comment Section -->
|
||||||
|
<section class="comment-section">
|
||||||
|
<div class="comment-container">
|
||||||
|
<h3>Comments</h3>
|
||||||
|
|
||||||
|
<!-- ATProto Auth Widget Container -->
|
||||||
|
<div id="atproto-auth-widget" class="comment-auth"></div>
|
||||||
|
|
||||||
|
<div id="commentForm" class="comment-form" style="display: none;">
|
||||||
|
<textarea id="commentText" placeholder="Share your thoughts..." rows="4"></textarea>
|
||||||
|
<button onclick="submitComment()" class="submit-btn">Post Comment</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="commentsList" class="comments-list">
|
||||||
|
<!-- Comments will be loaded here -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<aside class="article-sidebar">
|
||||||
|
<nav class="toc">
|
||||||
|
<h3>Contents</h3>
|
||||||
|
<div id="toc-content">
|
||||||
|
<!-- TOC will be generated by JavaScript -->
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
<!-- Include ATProto Libraries via script tags (more reliable than dynamic imports) -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@atproto/oauth-client-browser@latest/dist/index.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@atproto/api@latest/dist/index.js"></script>
|
||||||
|
|
||||||
|
<!-- Fallback: Try multiple CDNs -->
|
||||||
|
<script>
|
||||||
|
console.log('Checking ATProto library availability...');
|
||||||
|
|
||||||
|
// Check if libraries loaded successfully
|
||||||
|
if (typeof ATProto === 'undefined' && typeof window.ATProto === 'undefined') {
|
||||||
|
console.log('Primary CDN failed, trying fallback...');
|
||||||
|
|
||||||
|
// Create fallback script elements
|
||||||
|
const fallbackScripts = [
|
||||||
|
'https://unpkg.com/@atproto/oauth-client-browser@latest/dist/index.js',
|
||||||
|
'https://esm.sh/@atproto/oauth-client-browser',
|
||||||
|
'https://cdn.skypack.dev/@atproto/oauth-client-browser'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Load fallback scripts sequentially
|
||||||
|
let scriptIndex = 0;
|
||||||
|
function loadNextScript() {
|
||||||
|
if (scriptIndex < fallbackScripts.length) {
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.src = fallbackScripts[scriptIndex];
|
||||||
|
script.onload = () => {
|
||||||
|
console.log(`Loaded from fallback CDN: ${fallbackScripts[scriptIndex]}`);
|
||||||
|
window.atprotoLibrariesReady = true;
|
||||||
|
};
|
||||||
|
script.onerror = () => {
|
||||||
|
console.log(`Failed to load from: ${fallbackScripts[scriptIndex]}`);
|
||||||
|
scriptIndex++;
|
||||||
|
loadNextScript();
|
||||||
|
};
|
||||||
|
document.head.appendChild(script);
|
||||||
|
} else {
|
||||||
|
console.error('All CDN fallbacks failed');
|
||||||
|
window.atprotoLibrariesReady = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadNextScript();
|
||||||
|
} else {
|
||||||
|
console.log('✅ ATProto libraries loaded from primary CDN');
|
||||||
|
window.atprotoLibrariesReady = true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Simple ATProto Widget (no external dependency) -->
|
||||||
|
<link rel="stylesheet" href="/atproto-auth-widget/dist/atproto-auth.min.css">
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Initialize auth widget
|
||||||
|
let authWidget = null;
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
generateTableOfContents();
|
||||||
|
initializeAuthWidget();
|
||||||
|
loadComments();
|
||||||
|
});
|
||||||
|
|
||||||
|
function generateTableOfContents() {
|
||||||
|
const tocContainer = document.getElementById('toc-content');
|
||||||
|
const headings = document.querySelectorAll('.article-body h1, .article-body h2, .article-body h3, .article-body h4, .article-body h5, .article-body h6');
|
||||||
|
|
||||||
|
if (headings.length === 0) {
|
||||||
|
tocContainer.innerHTML = '<p class="no-toc">No headings found</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tocList = document.createElement('ul');
|
||||||
|
tocList.className = 'toc-list';
|
||||||
|
|
||||||
|
headings.forEach((heading, index) => {
|
||||||
|
const id = `heading-${index}`;
|
||||||
|
heading.id = id;
|
||||||
|
|
||||||
|
const listItem = document.createElement('li');
|
||||||
|
listItem.className = `toc-item toc-${heading.tagName.toLowerCase()}`;
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = `#${id}`;
|
||||||
|
link.textContent = heading.textContent;
|
||||||
|
link.className = 'toc-link';
|
||||||
|
|
||||||
|
// Smooth scroll behavior
|
||||||
|
link.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
heading.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
|
||||||
|
listItem.appendChild(link);
|
||||||
|
tocList.appendChild(listItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
tocContainer.appendChild(tocList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize ATProto Auth Widget
|
||||||
|
async function initializeAuthWidget() {
|
||||||
|
try {
|
||||||
|
// Check WebCrypto API availability
|
||||||
|
console.log('WebCrypto check:', {
|
||||||
|
available: !!window.crypto && !!window.crypto.subtle,
|
||||||
|
secureContext: window.isSecureContext,
|
||||||
|
protocol: window.location.protocol,
|
||||||
|
hostname: window.location.hostname
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!window.crypto || !window.crypto.subtle) {
|
||||||
|
throw new Error('WebCrypto API is not available. This requires HTTPS or localhost.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window.isSecureContext) {
|
||||||
|
console.warn('Not in secure context - WebCrypto may not work properly');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simplified approach: Show manual OAuth form
|
||||||
|
console.log('Using simplified OAuth approach...');
|
||||||
|
showSimpleOAuthForm();
|
||||||
|
// Fallback to widget initialization
|
||||||
|
authWidget = await window.initATProtoWidget('#atproto-auth-widget', {
|
||||||
|
clientId: clientId,
|
||||||
|
onLogin: (session) => {
|
||||||
|
console.log('User logged in:', session.handle);
|
||||||
|
document.getElementById('commentForm').style.display = 'block';
|
||||||
|
},
|
||||||
|
onLogout: () => {
|
||||||
|
console.log('User logged out');
|
||||||
|
document.getElementById('commentForm').style.display = 'none';
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error('ATProto Auth Error:', error);
|
||||||
|
// Show user-friendly error message
|
||||||
|
const authContainer = document.getElementById('atproto-auth-widget');
|
||||||
|
if (authContainer) {
|
||||||
|
let errorMessage = 'Authentication service is temporarily unavailable.';
|
||||||
|
let suggestion = 'Please try refreshing the page.';
|
||||||
|
|
||||||
|
if (error.message && error.message.includes('WebCrypto')) {
|
||||||
|
errorMessage = 'This feature requires a secure HTTPS connection.';
|
||||||
|
suggestion = 'Please ensure you are accessing via https://log.syui.ai';
|
||||||
|
}
|
||||||
|
|
||||||
|
authContainer.innerHTML = `
|
||||||
|
<div class="atproto-auth__fallback">
|
||||||
|
<p>${errorMessage}</p>
|
||||||
|
<p>${suggestion}</p>
|
||||||
|
<details style="margin-top: 10px; font-size: 0.8em; color: #666;">
|
||||||
|
<summary>Technical details</summary>
|
||||||
|
<pre>${error.message || 'Unknown error'}</pre>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
theme: 'default'
|
||||||
|
});
|
||||||
|
} else if (typeof window.ATProtoAuthWidget === 'function') {
|
||||||
|
// Fallback to direct widget initialization
|
||||||
|
authWidget = new window.ATProtoAuthWidget({
|
||||||
|
containerSelector: '#atproto-auth-widget',
|
||||||
|
clientId: clientId,
|
||||||
|
onLogin: (session) => {
|
||||||
|
console.log('User logged in:', session.handle);
|
||||||
|
document.getElementById('commentForm').style.display = 'block';
|
||||||
|
},
|
||||||
|
onLogout: () => {
|
||||||
|
console.log('User logged out');
|
||||||
|
document.getElementById('commentForm').style.display = 'none';
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error('ATProto Auth Error:', error);
|
||||||
|
const authContainer = document.getElementById('atproto-auth-widget');
|
||||||
|
if (authContainer) {
|
||||||
|
authContainer.innerHTML = `
|
||||||
|
<div class="atproto-auth__fallback">
|
||||||
|
<p>Authentication service is temporarily unavailable.</p>
|
||||||
|
<p>Please try refreshing the page.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
theme: 'default'
|
||||||
|
});
|
||||||
|
await authWidget.init();
|
||||||
|
} else {
|
||||||
|
throw new Error('ATProto widget not available');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize auth widget:', error);
|
||||||
|
// Show fallback UI
|
||||||
|
const authContainer = document.getElementById('atproto-auth-widget');
|
||||||
|
if (authContainer) {
|
||||||
|
authContainer.innerHTML = `
|
||||||
|
<div class="atproto-auth__fallback">
|
||||||
|
<p>Authentication widget failed to load.</p>
|
||||||
|
<p>Please check your internet connection and refresh the page.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitComment() {
|
||||||
|
const commentText = document.getElementById('commentText').value.trim();
|
||||||
|
if (!commentText || !authWidget.isLoggedIn()) {
|
||||||
|
alert('Please login and enter a comment');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const postSlug = '{{ post.slug }}';
|
||||||
|
const postUrl = window.location.href;
|
||||||
|
const createdAt = new Date().toISOString();
|
||||||
|
|
||||||
|
// Create comment record using the auth widget
|
||||||
|
const response = await authWidget.createRecord('ai.log.comment', {
|
||||||
|
$type: 'ai.log.comment',
|
||||||
|
text: commentText,
|
||||||
|
post_slug: postSlug,
|
||||||
|
post_url: postUrl,
|
||||||
|
createdAt: createdAt
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Comment posted:', response);
|
||||||
|
document.getElementById('commentText').value = '';
|
||||||
|
loadComments();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Comment submission failed:', error);
|
||||||
|
alert('Failed to post comment: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAuthenticatedState(session) {
|
||||||
|
const authContainer = document.getElementById('atproto-auth-widget');
|
||||||
|
const agent = new window.ATProtoAgent(session);
|
||||||
|
|
||||||
|
authContainer.innerHTML = `
|
||||||
|
<div class="atproto-auth__authenticated">
|
||||||
|
<p>✅ Authenticated as: <strong>${session.did}</strong></p>
|
||||||
|
<button id="logout-btn" class="atproto-auth__button">Logout</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.getElementById('logout-btn').onclick = async () => {
|
||||||
|
await session.signOut();
|
||||||
|
window.location.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Show comment form
|
||||||
|
document.getElementById('commentForm').style.display = 'block';
|
||||||
|
window.currentSession = session;
|
||||||
|
window.currentAgent = agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoginForm(oauthClient) {
|
||||||
|
const authContainer = document.getElementById('atproto-auth-widget');
|
||||||
|
|
||||||
|
authContainer.innerHTML = `
|
||||||
|
<div class="atproto-auth__login">
|
||||||
|
<h4>Login with ATProto</h4>
|
||||||
|
<input type="text" id="handle-input" placeholder="user.bsky.social" />
|
||||||
|
<button id="login-btn" class="atproto-auth__button">Connect</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.getElementById('login-btn').onclick = async () => {
|
||||||
|
const handle = document.getElementById('handle-input').value.trim();
|
||||||
|
if (!handle) {
|
||||||
|
alert('Please enter your handle');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = await oauthClient.authorize(handle);
|
||||||
|
window.open(url, '_self', 'noopener');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('OAuth authorization failed:', error);
|
||||||
|
alert('Authentication failed: ' + error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enter key support
|
||||||
|
document.getElementById('handle-input').onkeypress = (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
document.getElementById('login-btn').click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadComments() {
|
||||||
|
try {
|
||||||
|
const commentsList = document.getElementById('commentsList');
|
||||||
|
commentsList.innerHTML = '<p class="loading">Loading comments from ATProto network...</p>';
|
||||||
|
|
||||||
|
// In a real implementation, you would query an aggregation service
|
||||||
|
// For demo, show empty state
|
||||||
|
setTimeout(() => {
|
||||||
|
commentsList.innerHTML = '<p class="no-comments">Comments will appear here when posted via ATProto.</p>';
|
||||||
|
}, 1000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load comments:', error);
|
||||||
|
document.getElementById('commentsList').innerHTML = '<p class="error">Failed to load comments</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
196
my-blog/templates/post-simple.html
Normal file
196
my-blog/templates/post-simple.html
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ post.title }} - {{ config.title }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="article-container">
|
||||||
|
<article class="article-content">
|
||||||
|
<header class="article-header">
|
||||||
|
<h1 class="article-title">{{ post.title }}</h1>
|
||||||
|
<div class="article-meta">
|
||||||
|
<time class="article-date">{{ post.date }}</time>
|
||||||
|
{% if post.language %}
|
||||||
|
<span class="article-lang">{{ post.language }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="article-actions">
|
||||||
|
{% if post.markdown_url %}
|
||||||
|
<a href="{{ post.markdown_url }}" class="action-btn markdown-btn" title="View Markdown">
|
||||||
|
.md
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if post.translation_url %}
|
||||||
|
<a href="{{ post.translation_url }}" class="action-btn translation-btn" title="View Translation">
|
||||||
|
🌐 {% if post.language == 'ja' %}English{% else %}日本語{% endif %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="article-body">
|
||||||
|
{{ post.content | safe }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Simple Comment Section -->
|
||||||
|
<section class="comment-section">
|
||||||
|
<div class="comment-container">
|
||||||
|
<h3>Comments</h3>
|
||||||
|
|
||||||
|
<!-- Simple OAuth Button -->
|
||||||
|
<div class="simple-oauth">
|
||||||
|
<p>📝 To comment, authenticate with Bluesky:</p>
|
||||||
|
<button id="bluesky-auth" class="oauth-button">
|
||||||
|
🦋 Login with Bluesky
|
||||||
|
</button>
|
||||||
|
<p class="oauth-note">
|
||||||
|
<small>After authentication, you can post comments that will be stored in your ATProto PDS.</small>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="comments-list" class="comments-list">
|
||||||
|
<p class="no-comments">Comments will appear here when posted via ATProto.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<aside class="article-sidebar">
|
||||||
|
<nav class="toc">
|
||||||
|
<h3>Contents</h3>
|
||||||
|
<div id="toc-content">
|
||||||
|
<!-- TOC will be generated by JavaScript -->
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
generateTableOfContents();
|
||||||
|
initializeSimpleAuth();
|
||||||
|
});
|
||||||
|
|
||||||
|
function generateTableOfContents() {
|
||||||
|
const tocContainer = document.getElementById('toc-content');
|
||||||
|
const headings = document.querySelectorAll('.article-body h1, .article-body h2, .article-body h3, .article-body h4, .article-body h5, .article-body h6');
|
||||||
|
|
||||||
|
if (headings.length === 0) {
|
||||||
|
tocContainer.innerHTML = '<p class="no-toc">No headings found</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tocList = document.createElement('ul');
|
||||||
|
tocList.className = 'toc-list';
|
||||||
|
|
||||||
|
headings.forEach((heading, index) => {
|
||||||
|
const id = `heading-${index}`;
|
||||||
|
heading.id = id;
|
||||||
|
|
||||||
|
const listItem = document.createElement('li');
|
||||||
|
listItem.className = `toc-item toc-${heading.tagName.toLowerCase()}`;
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = `#${id}`;
|
||||||
|
link.textContent = heading.textContent;
|
||||||
|
link.className = 'toc-link';
|
||||||
|
|
||||||
|
link.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
heading.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
|
||||||
|
listItem.appendChild(link);
|
||||||
|
tocList.appendChild(listItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
tocContainer.appendChild(tocList);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeSimpleAuth() {
|
||||||
|
const authButton = document.getElementById('bluesky-auth');
|
||||||
|
|
||||||
|
authButton.addEventListener('click', function() {
|
||||||
|
// Simple approach: Direct redirect to Bluesky OAuth
|
||||||
|
const isProduction = window.location.hostname === 'log.syui.ai';
|
||||||
|
const clientId = isProduction
|
||||||
|
? 'https://log.syui.ai/client-metadata.json'
|
||||||
|
: window.location.origin + '/client-metadata.json';
|
||||||
|
|
||||||
|
const authUrl = `https://bsky.social/oauth/authorize?` +
|
||||||
|
`client_id=${encodeURIComponent(clientId)}&` +
|
||||||
|
`redirect_uri=${encodeURIComponent(window.location.href)}&` +
|
||||||
|
`response_type=code&` +
|
||||||
|
`scope=atproto%20transition:generic&` +
|
||||||
|
`state=demo-state`;
|
||||||
|
|
||||||
|
console.log('Redirecting to:', authUrl);
|
||||||
|
|
||||||
|
// Open in new tab for now (safer for testing)
|
||||||
|
window.open(authUrl, '_blank');
|
||||||
|
|
||||||
|
// Show status message
|
||||||
|
authButton.innerHTML = '✅ Check the new tab for authentication';
|
||||||
|
authButton.disabled = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if we're returning from OAuth
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
if (urlParams.has('code')) {
|
||||||
|
console.log('OAuth callback detected:', urlParams.get('code'));
|
||||||
|
document.querySelector('.simple-oauth').innerHTML = `
|
||||||
|
<div class="oauth-success">
|
||||||
|
✅ OAuth callback received!<br>
|
||||||
|
<small>Code: ${urlParams.get('code')}</small><br>
|
||||||
|
<small>In a full implementation, this would exchange the code for tokens.</small>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.simple-oauth {
|
||||||
|
background: #f8f9fa;
|
||||||
|
border: 1px solid #e9ecef;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oauth-button {
|
||||||
|
background: #1185fe;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oauth-button:hover {
|
||||||
|
background: #0d6efd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oauth-button:disabled {
|
||||||
|
background: #6c757d;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oauth-note {
|
||||||
|
color: #6c757d;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oauth-success {
|
||||||
|
background: #d1edff;
|
||||||
|
border: 1px solid #b6d7ff;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 15px;
|
||||||
|
color: #0c5460;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
93
my-blog/templates/post.html
Normal file
93
my-blog/templates/post.html
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ post.title }} - {{ config.title }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="article-container">
|
||||||
|
<article class="article-content">
|
||||||
|
<header class="article-header">
|
||||||
|
<h1 class="article-title">{{ post.title }}</h1>
|
||||||
|
<div class="article-meta">
|
||||||
|
<time class="article-date">{{ post.date }}</time>
|
||||||
|
{% if post.language %}
|
||||||
|
<span class="article-lang">{{ post.language }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="article-actions">
|
||||||
|
{% if post.markdown_url %}
|
||||||
|
<a href="{{ post.markdown_url }}" class="action-btn markdown-btn" title="View Markdown">
|
||||||
|
.md
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if post.translation_url %}
|
||||||
|
<a href="{{ post.translation_url }}" class="action-btn translation-btn" title="View Translation">
|
||||||
|
🌐 {% if post.language == 'ja' %}English{% else %}日本語{% endif %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="article-body">
|
||||||
|
{{ post.content | safe }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="comment-atproto"></div>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<aside class="article-sidebar">
|
||||||
|
<nav class="toc">
|
||||||
|
<h3>Contents</h3>
|
||||||
|
<div id="toc-content">
|
||||||
|
<!-- TOC will be generated by JavaScript -->
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Generate table of contents
|
||||||
|
function generateTableOfContents() {
|
||||||
|
const tocContainer = document.getElementById('toc-content');
|
||||||
|
const headings = document.querySelectorAll('.article-body h1, .article-body h2, .article-body h3, .article-body h4, .article-body h5, .article-body h6');
|
||||||
|
|
||||||
|
if (headings.length === 0) {
|
||||||
|
tocContainer.innerHTML = '<p class="no-toc">No headings found</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tocList = document.createElement('ul');
|
||||||
|
tocList.className = 'toc-list';
|
||||||
|
|
||||||
|
headings.forEach((heading, index) => {
|
||||||
|
const id = `heading-${index}`;
|
||||||
|
heading.id = id;
|
||||||
|
|
||||||
|
const listItem = document.createElement('li');
|
||||||
|
listItem.className = `toc-item toc-${heading.tagName.toLowerCase()}`;
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = `#${id}`;
|
||||||
|
link.textContent = heading.textContent;
|
||||||
|
link.className = 'toc-link';
|
||||||
|
|
||||||
|
link.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
heading.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
|
||||||
|
listItem.appendChild(link);
|
||||||
|
tocList.appendChild(listItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
tocContainer.appendChild(tocList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize on page load
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
generateTableOfContents();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
{% endblock %}
|
21
oauth/.env.production
Normal file
21
oauth/.env.production
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Handle-based Configuration (DIDs resolved at runtime)
|
||||||
|
VITE_ATPROTO_PDS=syu.is
|
||||||
|
VITE_ADMIN_HANDLE=ai.syui.ai
|
||||||
|
VITE_AI_HANDLE=ai.syui.ai
|
||||||
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||||
|
VITE_ATPROTO_WEB_URL=https://bsky.app
|
||||||
|
VITE_ATPROTO_HANDLE_LIST=["syui.syui.ai","ai.syui.ai","ai.ai"]
|
||||||
|
|
||||||
|
# AI Configuration
|
||||||
|
VITE_AI_ENABLED=true
|
||||||
|
VITE_AI_ASK_AI=true
|
||||||
|
VITE_AI_PROVIDER=ollama
|
||||||
|
VITE_AI_MODEL=gemma3:1b
|
||||||
|
VITE_AI_HOST=https://ollama.syui.ai
|
||||||
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
|
|
@@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "aicard",
|
"name": "aicard",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --mode development",
|
"dev": "vite --mode development",
|
||||||
"build": "vite build --mode production",
|
"build": "vite build --mode production",
|
||||||
"build:dev": "vite build --mode development",
|
"build:dev": "vite build --mode development",
|
||||||
"build:local": "VITE_APP_HOST=http://localhost:4173 vite build --mode development",
|
"build:local": "VITE_APP_HOST=http://localhost:4173 vite build --mode development",
|
||||||
"preview": "vite preview"
|
"preview": "npm run test:console && vite preview",
|
||||||
|
"test": "vitest",
|
||||||
|
"test:console": "node -r esbuild-register src/tests/console-test.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@atproto/api": "^0.15.12",
|
"@atproto/api": "^0.15.12",
|
||||||
@@ -26,6 +28,9 @@
|
|||||||
"@types/react-dom": "^18.2.18",
|
"@types/react-dom": "^18.2.18",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.0.10"
|
"vite": "^5.0.10",
|
||||||
|
"vitest": "^1.1.0",
|
||||||
|
"esbuild": "^0.19.10",
|
||||||
|
"esbuild-register": "^3.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
14
oauth/public/.well-known/jwks.json
Normal file
14
oauth/public/.well-known/jwks.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"keys": [
|
||||||
|
{
|
||||||
|
"kty": "EC",
|
||||||
|
"crv": "P-256",
|
||||||
|
"x": "mock_x_coordinate_base64url",
|
||||||
|
"y": "mock_y_coordinate_base64url",
|
||||||
|
"d": "mock_private_key_base64url",
|
||||||
|
"use": "sig",
|
||||||
|
"kid": "ai-card-oauth-key-1",
|
||||||
|
"alg": "ES256"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
24
oauth/public/client-metadata.json
Normal file
24
oauth/public/client-metadata.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"client_id": "https://syui.ai/client-metadata.json",
|
||||||
|
"client_name": "ai.log",
|
||||||
|
"client_uri": "https://syui.ai",
|
||||||
|
"logo_uri": "https://syui.ai/favicon.ico",
|
||||||
|
"tos_uri": "https://syui.ai/terms",
|
||||||
|
"policy_uri": "https://syui.ai/privacy",
|
||||||
|
"redirect_uris": [
|
||||||
|
"https://syui.ai/oauth/callback",
|
||||||
|
"https://syui.ai/"
|
||||||
|
],
|
||||||
|
"response_types": [
|
||||||
|
"code"
|
||||||
|
],
|
||||||
|
"grant_types": [
|
||||||
|
"authorization_code",
|
||||||
|
"refresh_token"
|
||||||
|
],
|
||||||
|
"token_endpoint_auth_method": "none",
|
||||||
|
"scope": "atproto transition:generic",
|
||||||
|
"subject_type": "public",
|
||||||
|
"application_type": "web",
|
||||||
|
"dpop_bound_access_tokens": true
|
||||||
|
}
|
@@ -1,7 +1,16 @@
|
|||||||
|
/* Theme Colors */
|
||||||
|
:root {
|
||||||
|
--theme-color: #FF4500;
|
||||||
|
--white: #fff;
|
||||||
|
--light-gray: #aaa;
|
||||||
|
--dark-gray: #666;
|
||||||
|
--background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.app {
|
.app {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
|
background: linear-gradient(180deg, #f8f9fa 0%, var(--background) 100%);
|
||||||
color: #333333;
|
color: var(--dark-gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-header {
|
.app-header {
|
||||||
@@ -41,15 +50,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-button.active {
|
.nav-button.active {
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: 1px solid #667eea;
|
border: 1px solid var(--theme-color);
|
||||||
box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
|
box-shadow: 0 4px 16px rgba(255, 69, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-button.active:hover {
|
.nav-button.active:hover {
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
|
box-shadow: 0 6px 20px rgba(255, 69, 0, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-header h1 {
|
.app-header h1 {
|
||||||
@@ -99,9 +108,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.login-button {
|
.login-button {
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: 1px solid #667eea;
|
border: 1px solid var(--theme-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.backup-button {
|
.backup-button {
|
||||||
@@ -124,7 +133,7 @@
|
|||||||
|
|
||||||
.login-button:hover {
|
.login-button:hover {
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
box-shadow: 0 4px 12px rgba(255, 69, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.backup-button:hover {
|
.backup-button:hover {
|
||||||
@@ -153,11 +162,76 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.app-main {
|
.app-main {
|
||||||
max-width: 1200px;
|
max-width: 1000px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 40px 20px;
|
padding: 40px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1000px) {
|
||||||
|
* {
|
||||||
|
max-width: 100% !important;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app .app-main {
|
||||||
|
max-width: 100% !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-item {
|
||||||
|
padding: 0px !important;
|
||||||
|
margin: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comments-list {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-section {
|
||||||
|
padding: 30px 0 !important;
|
||||||
|
margin: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content {
|
||||||
|
padding: 10px !important;
|
||||||
|
word-wrap: break-word !important;
|
||||||
|
overflow-wrap: break-word !important;
|
||||||
|
white-space: pre-wrap !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-header {
|
||||||
|
padding: 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix overflow on article pages */
|
||||||
|
article.article-content {
|
||||||
|
overflow-x: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure full width on mobile */
|
||||||
|
.app {
|
||||||
|
max-width: 100vw !important;
|
||||||
|
overflow-x: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix button overflow */
|
||||||
|
button {
|
||||||
|
max-width: 100%;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix comment-meta URI overflow */
|
||||||
|
.comment-meta {
|
||||||
|
word-break: break-all !important;
|
||||||
|
overflow-wrap: break-word !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.gacha-section {
|
.gacha-section {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 60px;
|
margin-bottom: 60px;
|
||||||
@@ -255,9 +329,18 @@
|
|||||||
.comment-section {
|
.comment-section {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 20px;
|
/* padding: 20px; - removed to avoid double padding */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.comment-section {
|
||||||
|
max-width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.auth-section {
|
.auth-section {
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
border: 1px solid #e9ecef;
|
border: 1px solid #e9ecef;
|
||||||
@@ -267,9 +350,41 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout .handle-input {
|
||||||
|
flex: 1;
|
||||||
|
margin: 0;
|
||||||
|
padding: 10px 15px;
|
||||||
|
font-size: 16px;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
border-radius: 6px 0 0 6px;
|
||||||
|
background: white;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout .handle-input:focus {
|
||||||
|
border-color: var(--theme-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout .atproto-button {
|
||||||
|
margin: 0;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 0 6px 6px 0;
|
||||||
|
min-width: 50px;
|
||||||
|
font-weight: bold;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.atproto-button {
|
.atproto-button {
|
||||||
background: #1185fe;
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: none;
|
border: none;
|
||||||
padding: 12px 24px;
|
padding: 12px 24px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
@@ -281,9 +396,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.atproto-button:hover {
|
.atproto-button:hover {
|
||||||
background: #0d6efd;
|
filter: brightness(1.1);
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 4px 12px rgba(17, 133, 254, 0.4);
|
box-shadow: 0 4px 12px rgba(255, 69, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.username-input-section {
|
.username-input-section {
|
||||||
@@ -300,6 +415,30 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Override for search bar layout */
|
||||||
|
.search-bar-layout .handle-input {
|
||||||
|
width: auto;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile responsive for search bar */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.auth-section.search-bar-layout {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout .handle-input {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-section.search-bar-layout .atproto-button {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.auth-hint {
|
.auth-hint {
|
||||||
color: #6c757d;
|
color: #6c757d;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@@ -407,8 +546,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post-button {
|
.post-button {
|
||||||
background: #28a745;
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: none;
|
border: none;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
@@ -419,9 +558,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post-button:hover:not(:disabled) {
|
.post-button:hover:not(:disabled) {
|
||||||
background: #218838;
|
filter: brightness(1.1);
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
|
box-shadow: 0 4px 12px rgba(255, 69, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-button:disabled {
|
.post-button:disabled {
|
||||||
@@ -432,9 +571,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comments-list {
|
.comments-list {
|
||||||
border: 1px solid #ddd;
|
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 20px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comments-header {
|
.comments-header {
|
||||||
@@ -455,8 +593,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comments-toggle-button {
|
.comments-toggle-button {
|
||||||
background: #1185fe;
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: none;
|
border: none;
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
@@ -467,9 +605,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comments-toggle-button:hover {
|
.comments-toggle-button:hover {
|
||||||
background: #0d6efd;
|
filter: brightness(1.1);
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 4px 12px rgba(17, 133, 254, 0.4);
|
box-shadow: 0 4px 12px rgba(255, 69, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment-item {
|
.comment-item {
|
||||||
@@ -524,10 +662,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.delete-button {
|
.delete-button {
|
||||||
background: none;
|
background: #dc3545;
|
||||||
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 16px;
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
@@ -535,14 +675,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.delete-button:hover {
|
.delete-button:hover {
|
||||||
background: rgba(220, 53, 69, 0.1);
|
background: #c82333;
|
||||||
transform: scale(1.1);
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment-content {
|
.comment-content {
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
color: #333;
|
color: #333;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment-meta {
|
.comment-meta {
|
||||||
@@ -712,8 +854,8 @@
|
|||||||
|
|
||||||
/* JSON Display Styles */
|
/* JSON Display Styles */
|
||||||
.json-button {
|
.json-button {
|
||||||
background: #4caf50;
|
background: var(--theme-color);
|
||||||
color: white;
|
color: var(--white);
|
||||||
border: none;
|
border: none;
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@@ -724,7 +866,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.json-button:hover {
|
.json-button:hover {
|
||||||
background: #45a049;
|
filter: brightness(1.1);
|
||||||
transform: scale(1.05);
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,4 +899,90 @@
|
|||||||
color: #333;
|
color: #333;
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tab Navigation */
|
||||||
|
.tab-navigation {
|
||||||
|
display: flex;
|
||||||
|
border-bottom: 2px solid #e1e5e9;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 12px 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #656d76;
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-button:hover {
|
||||||
|
color: var(--theme-color);
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-button.active {
|
||||||
|
color: var(--theme-color);
|
||||||
|
border-bottom-color: var(--theme-color);
|
||||||
|
background: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.chat-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-type-button {
|
||||||
|
background: var(--theme-color);
|
||||||
|
color: var(--white);
|
||||||
|
border: none;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: default;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-type-text {
|
||||||
|
font-size: 16px;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.chat-date {
|
||||||
|
color: #656d76;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-content {
|
||||||
|
background: #f6f8fa;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
border-left: 4px solid #d1d9e0;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-meta {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #656d76;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-chat {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 20px;
|
||||||
|
color: #656d76;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-message.comment-style {
|
||||||
|
border-left: 4px solid var(--theme-color);
|
||||||
|
}
|
1622
oauth/src/App.tsx
Normal file
1622
oauth/src/App.tsx
Normal file
File diff suppressed because it is too large
Load Diff
21
oauth/src/components/AIChat-access.tsx
Normal file
21
oauth/src/components/AIChat-access.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Cloudflare Access対応版の例
|
||||||
|
const response = await fetch(`${aiConfig.host}/api/generate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
// Cloudflare Access Service Token
|
||||||
|
'CF-Access-Client-Id': import.meta.env.VITE_CF_ACCESS_CLIENT_ID,
|
||||||
|
'CF-Access-Client-Secret': import.meta.env.VITE_CF_ACCESS_CLIENT_SECRET,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: aiConfig.model,
|
||||||
|
prompt: prompt,
|
||||||
|
stream: false,
|
||||||
|
options: {
|
||||||
|
temperature: 0.9,
|
||||||
|
top_p: 0.9,
|
||||||
|
num_predict: 200,
|
||||||
|
repeat_penalty: 1.1,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
271
oauth/src/components/AIChat.tsx
Normal file
271
oauth/src/components/AIChat.tsx
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { User } from '../services/auth';
|
||||||
|
import { atprotoOAuthService } from '../services/atproto-oauth';
|
||||||
|
import { appConfig, getCollectionNames } from '../config/app';
|
||||||
|
|
||||||
|
interface AIChatProps {
|
||||||
|
user: User | null;
|
||||||
|
isEnabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AIChat: React.FC<AIChatProps> = ({ user, isEnabled }) => {
|
||||||
|
const [chatHistory, setChatHistory] = useState<any[]>([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isProcessing, setIsProcessing] = useState(false);
|
||||||
|
const [aiProfile, setAiProfile] = useState<any>(null);
|
||||||
|
|
||||||
|
// Get AI settings from appConfig (unified configuration)
|
||||||
|
const aiConfig = {
|
||||||
|
enabled: appConfig.aiEnabled,
|
||||||
|
askAi: appConfig.aiAskAi,
|
||||||
|
provider: appConfig.aiProvider,
|
||||||
|
model: appConfig.aiModel,
|
||||||
|
host: appConfig.aiHost,
|
||||||
|
systemPrompt: appConfig.aiSystemPrompt,
|
||||||
|
aiDid: appConfig.aiDid,
|
||||||
|
bskyPublicApi: appConfig.bskyPublicApi,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetch AI profile on load
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchAIProfile = async () => {
|
||||||
|
if (!aiConfig.aiDid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try with agent first
|
||||||
|
const agent = atprotoOAuthService.getAgent();
|
||||||
|
if (agent) {
|
||||||
|
const profile = await agent.getProfile({ actor: aiConfig.aiDid });
|
||||||
|
const profileData = {
|
||||||
|
did: aiConfig.aiDid,
|
||||||
|
handle: profile.data.handle,
|
||||||
|
displayName: profile.data.displayName,
|
||||||
|
avatar: profile.data.avatar,
|
||||||
|
description: profile.data.description
|
||||||
|
};
|
||||||
|
setAiProfile(profileData);
|
||||||
|
|
||||||
|
// Dispatch event to update Ask AI button
|
||||||
|
window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: profileData }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to public API
|
||||||
|
const response = await fetch(`${aiConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(aiConfig.aiDid)}`);
|
||||||
|
if (response.ok) {
|
||||||
|
const profileData = await response.json();
|
||||||
|
const profile = {
|
||||||
|
did: aiConfig.aiDid,
|
||||||
|
handle: profileData.handle,
|
||||||
|
displayName: profileData.displayName,
|
||||||
|
avatar: profileData.avatar,
|
||||||
|
description: profileData.description
|
||||||
|
};
|
||||||
|
setAiProfile(profile);
|
||||||
|
|
||||||
|
// Dispatch event to update Ask AI button
|
||||||
|
window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: profile }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setAiProfile(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchAIProfile();
|
||||||
|
}, [aiConfig.aiDid]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEnabled || !aiConfig.askAi) return;
|
||||||
|
|
||||||
|
// Listen for AI question posts from base.html
|
||||||
|
const handleAIQuestion = async (event: any) => {
|
||||||
|
if (!user || !event.detail || !event.detail.question || isProcessing || !aiProfile) return;
|
||||||
|
|
||||||
|
setIsProcessing(true);
|
||||||
|
try {
|
||||||
|
await postQuestionAndGenerateResponse(event.detail.question);
|
||||||
|
} finally {
|
||||||
|
setIsProcessing(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add listener with a small delay to ensure it's ready
|
||||||
|
setTimeout(() => {
|
||||||
|
window.addEventListener('postAIQuestion', handleAIQuestion);
|
||||||
|
|
||||||
|
// Notify that AI is ready
|
||||||
|
window.dispatchEvent(new CustomEvent('aiChatReady'));
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('postAIQuestion', handleAIQuestion);
|
||||||
|
};
|
||||||
|
}, [user, isEnabled, isProcessing, aiProfile]);
|
||||||
|
|
||||||
|
const postQuestionAndGenerateResponse = async (question: string) => {
|
||||||
|
if (!user || !aiConfig.askAi || !aiProfile) return;
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const agent = atprotoOAuthService.getAgent();
|
||||||
|
if (!agent) throw new Error('No agent available');
|
||||||
|
|
||||||
|
// Get collection names
|
||||||
|
const collections = getCollectionNames(appConfig.collections.base);
|
||||||
|
|
||||||
|
// 1. Post question to ATProto
|
||||||
|
const now = new Date();
|
||||||
|
const rkey = now.toISOString().replace(/[:.]/g, '-');
|
||||||
|
|
||||||
|
// Extract post metadata from current page
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const postSlug = currentUrl.match(/\/posts\/([^/]+)/)?.[1] || '';
|
||||||
|
const postTitle = document.title.replace(' - syui.ai', '') || '';
|
||||||
|
|
||||||
|
const questionRecord = {
|
||||||
|
$type: collections.chat,
|
||||||
|
post: {
|
||||||
|
url: currentUrl,
|
||||||
|
slug: postSlug,
|
||||||
|
title: postTitle,
|
||||||
|
date: new Date().toISOString(),
|
||||||
|
tags: [],
|
||||||
|
language: "ja"
|
||||||
|
},
|
||||||
|
type: "question",
|
||||||
|
text: question,
|
||||||
|
author: {
|
||||||
|
did: user.did,
|
||||||
|
handle: user.handle,
|
||||||
|
avatar: user.avatar,
|
||||||
|
displayName: user.displayName || user.handle,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
await agent.api.com.atproto.repo.putRecord({
|
||||||
|
repo: user.did,
|
||||||
|
collection: collections.chat,
|
||||||
|
rkey: rkey,
|
||||||
|
record: questionRecord,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Get chat history
|
||||||
|
const chatRecords = await agent.api.com.atproto.repo.listRecords({
|
||||||
|
repo: user.did,
|
||||||
|
collection: collections.chat,
|
||||||
|
limit: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
let chatHistoryText = '';
|
||||||
|
if (chatRecords.data.records) {
|
||||||
|
chatHistoryText = chatRecords.data.records
|
||||||
|
.map((r: any) => {
|
||||||
|
if (r.value.type === 'question') {
|
||||||
|
return `User: ${r.value.text}`;
|
||||||
|
} else if (r.value.type === 'answer') {
|
||||||
|
return `AI: ${r.value.text}`;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Generate AI response based on provider
|
||||||
|
let aiAnswer = '';
|
||||||
|
|
||||||
|
// 3. Generate AI response using Ollama via proxy
|
||||||
|
if (aiConfig.provider === 'ollama') {
|
||||||
|
const prompt = `${aiConfig.systemPrompt}
|
||||||
|
|
||||||
|
Question: ${question}
|
||||||
|
|
||||||
|
Answer:`;
|
||||||
|
|
||||||
|
const response = await fetch(`${aiConfig.host}/api/generate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Origin': 'https://syui.ai',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: aiConfig.model,
|
||||||
|
prompt: prompt,
|
||||||
|
stream: false,
|
||||||
|
options: {
|
||||||
|
temperature: 0.9,
|
||||||
|
top_p: 0.9,
|
||||||
|
num_predict: 200, // Longer responses for better answers
|
||||||
|
repeat_penalty: 1.1,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('AI API request failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
aiAnswer = data.response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Immediately dispatch event to update UI
|
||||||
|
window.dispatchEvent(new CustomEvent('aiResponseReceived', {
|
||||||
|
detail: {
|
||||||
|
answer: aiAnswer,
|
||||||
|
aiProfile: aiProfile,
|
||||||
|
timestamp: now.toISOString()
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 5. Save AI response in background
|
||||||
|
const answerRkey = now.toISOString().replace(/[:.]/g, '-') + '-answer';
|
||||||
|
|
||||||
|
const answerRecord = {
|
||||||
|
$type: collections.chat,
|
||||||
|
post: {
|
||||||
|
url: currentUrl,
|
||||||
|
slug: postSlug,
|
||||||
|
title: postTitle,
|
||||||
|
date: new Date().toISOString(),
|
||||||
|
tags: [],
|
||||||
|
language: "ja"
|
||||||
|
},
|
||||||
|
type: "answer",
|
||||||
|
text: aiAnswer,
|
||||||
|
author: {
|
||||||
|
did: aiProfile.did,
|
||||||
|
handle: aiProfile.handle,
|
||||||
|
displayName: aiProfile.displayName,
|
||||||
|
avatar: aiProfile.avatar,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save to ATProto asynchronously (don't wait for it)
|
||||||
|
agent.api.com.atproto.repo.putRecord({
|
||||||
|
repo: user.did,
|
||||||
|
collection: collections.chat,
|
||||||
|
rkey: answerRkey,
|
||||||
|
record: answerRecord,
|
||||||
|
}).catch(err => {
|
||||||
|
// Silent fail for AI response saving
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
window.dispatchEvent(new CustomEvent('aiResponseError', {
|
||||||
|
detail: { error: 'AI応答の生成に失敗しました' }
|
||||||
|
}));
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This component doesn't render anything - it just handles the logic
|
||||||
|
return null;
|
||||||
|
};
|
79
oauth/src/components/AIProfile.tsx
Normal file
79
oauth/src/components/AIProfile.tsx
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { AtprotoAgent } from '@atproto/api';
|
||||||
|
|
||||||
|
interface AIProfile {
|
||||||
|
did: string;
|
||||||
|
handle: string;
|
||||||
|
displayName?: string;
|
||||||
|
avatar?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AIProfileProps {
|
||||||
|
aiDid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AIProfile: React.FC<AIProfileProps> = ({ aiDid }) => {
|
||||||
|
const [profile, setProfile] = useState<AIProfile | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchAIProfile = async () => {
|
||||||
|
try {
|
||||||
|
// Use public API to get profile information
|
||||||
|
const agent = new AtprotoAgent({ service: 'https://bsky.social' });
|
||||||
|
const response = await agent.getProfile({ actor: aiDid });
|
||||||
|
|
||||||
|
setProfile({
|
||||||
|
did: response.data.did,
|
||||||
|
handle: response.data.handle,
|
||||||
|
displayName: response.data.displayName,
|
||||||
|
avatar: response.data.avatar,
|
||||||
|
description: response.data.description,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Failed to fetch AI profile
|
||||||
|
// Fallback to basic info
|
||||||
|
setProfile({
|
||||||
|
did: aiDid,
|
||||||
|
handle: 'ai-assistant',
|
||||||
|
displayName: 'AI Assistant',
|
||||||
|
description: 'AI assistant for this blog',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (aiDid) {
|
||||||
|
fetchAIProfile();
|
||||||
|
}
|
||||||
|
}, [aiDid]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <div className="ai-profile-loading">Loading AI profile...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ai-profile">
|
||||||
|
<div className="ai-avatar">
|
||||||
|
{profile.avatar ? (
|
||||||
|
<img src={profile.avatar} alt={profile.displayName || profile.handle} />
|
||||||
|
) : (
|
||||||
|
<div className="ai-avatar-placeholder">🤖</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="ai-info">
|
||||||
|
<div className="ai-name">{profile.displayName || profile.handle}</div>
|
||||||
|
<div className="ai-handle">@{profile.handle}</div>
|
||||||
|
{profile.description && (
|
||||||
|
<div className="ai-description">{profile.description}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@@ -26,7 +26,7 @@ export const CardBox: React.FC<CardBoxProps> = ({ userDid }) => {
|
|||||||
const data = await atprotoOAuthService.getCardsFromBox();
|
const data = await atprotoOAuthService.getCardsFromBox();
|
||||||
setBoxData(data);
|
setBoxData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('カードボックス読み込みエラー:', err);
|
// Failed to load card box
|
||||||
setError(err instanceof Error ? err.message : 'カードボックスの読み込みに失敗しました');
|
setError(err instanceof Error ? err.message : 'カードボックスの読み込みに失敗しました');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -52,7 +52,7 @@ export const CardBox: React.FC<CardBoxProps> = ({ userDid }) => {
|
|||||||
setBoxData({ records: [] });
|
setBoxData({ records: [] });
|
||||||
alert('カードボックスを削除しました');
|
alert('カードボックスを削除しました');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('カードボックス削除エラー:', err);
|
// Failed to delete card box
|
||||||
setError(err instanceof Error ? err.message : 'カードボックスの削除に失敗しました');
|
setError(err instanceof Error ? err.message : 'カードボックスの削除に失敗しました');
|
||||||
} finally {
|
} finally {
|
||||||
setIsDeleting(false);
|
setIsDeleting(false);
|
@@ -32,7 +32,7 @@ export const CardList: React.FC = () => {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setMasterData(data);
|
setMasterData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error loading card master data:', err);
|
// Failed to load card master data
|
||||||
setError(err instanceof Error ? err.message : 'Failed to load card data');
|
setError(err instanceof Error ? err.message : 'Failed to load card data');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
@@ -29,7 +29,7 @@ export const CollectionAnalysis: React.FC<CollectionAnalysisProps> = ({ userDid
|
|||||||
const result = await aiCardApi.analyzeCollection(userDid);
|
const result = await aiCardApi.analyzeCollection(userDid);
|
||||||
setAnalysis(result);
|
setAnalysis(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Collection analysis failed:', err);
|
// Collection analysis failed
|
||||||
setError('AI分析機能を利用するにはai.gptサーバーが必要です。基本機能はai.cardサーバーのみで利用できます。');
|
setError('AI分析機能を利用するにはai.gptサーバーが必要です。基本機能はai.cardサーバーのみで利用できます。');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
@@ -48,7 +48,7 @@ export const GachaAnimation: React.FC<GachaAnimationProps> = ({
|
|||||||
await atprotoOAuthService.saveCardToCollection(card);
|
await atprotoOAuthService.saveCardToCollection(card);
|
||||||
alert('カードデータをatprotoコレクションに保存しました!');
|
alert('カードデータをatprotoコレクションに保存しました!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('保存エラー:', error);
|
// Failed to save card
|
||||||
alert('保存に失敗しました。認証が必要かもしれません。');
|
alert('保存に失敗しました。認証が必要かもしれません。');
|
||||||
} finally {
|
} finally {
|
||||||
setIsSharing(false);
|
setIsSharing(false);
|
@@ -30,7 +30,7 @@ export const GachaStats: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
result = await aiCardApi.getEnhancedStats();
|
result = await aiCardApi.getEnhancedStats();
|
||||||
} catch (aiError) {
|
} catch (aiError) {
|
||||||
console.warn('AI統計が利用できません、基本統計に切り替えます:', aiError);
|
// AI stats unavailable, using basic stats
|
||||||
setUseAI(false);
|
setUseAI(false);
|
||||||
result = await cardApi.getGachaStats();
|
result = await cardApi.getGachaStats();
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ export const GachaStats: React.FC = () => {
|
|||||||
}
|
}
|
||||||
setStats(result);
|
setStats(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Gacha stats failed:', err);
|
// Gacha stats failed
|
||||||
setError('統計データの取得に失敗しました。ai.cardサーバーが起動していることを確認してください。');
|
setError('統計データの取得に失敗しました。ai.cardサーバーが起動していることを確認してください。');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
@@ -160,7 +160,7 @@ export const Login: React.FC<LoginProps> = ({ onLogin, onClose, defaultHandle })
|
|||||||
/>
|
/>
|
||||||
<small>
|
<small>
|
||||||
メインパスワードではなく、
|
メインパスワードではなく、
|
||||||
<a href="https://bsky.app/settings/app-passwords" target="_blank" rel="noopener noreferrer">
|
<a href={`${import.meta.env.VITE_ATPROTO_WEB_URL || 'https://bsky.app'}/settings/app-passwords`} target="_blank" rel="noopener noreferrer">
|
||||||
アプリパスワード
|
アプリパスワード
|
||||||
</a>
|
</a>
|
||||||
を使用してください
|
を使用してください
|
@@ -7,8 +7,6 @@ interface OAuthCallbackProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError }) => {
|
export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError }) => {
|
||||||
console.log('=== OAUTH CALLBACK COMPONENT MOUNTED ===');
|
|
||||||
console.log('Current URL:', window.location.href);
|
|
||||||
|
|
||||||
const [isProcessing, setIsProcessing] = useState(true);
|
const [isProcessing, setIsProcessing] = useState(true);
|
||||||
const [needsHandle, setNeedsHandle] = useState(false);
|
const [needsHandle, setNeedsHandle] = useState(false);
|
||||||
@@ -18,12 +16,10 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Add timeout to prevent infinite loading
|
// Add timeout to prevent infinite loading
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
console.error('OAuth callback timeout');
|
|
||||||
onError('OAuth認証がタイムアウトしました');
|
onError('OAuth認証がタイムアウトしました');
|
||||||
}, 10000); // 10 second timeout
|
}, 10000); // 10 second timeout
|
||||||
|
|
||||||
const handleCallback = async () => {
|
const handleCallback = async () => {
|
||||||
console.log('=== HANDLE CALLBACK STARTED ===');
|
|
||||||
try {
|
try {
|
||||||
// Handle both query params (?) and hash params (#)
|
// Handle both query params (?) and hash params (#)
|
||||||
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
||||||
@@ -35,14 +31,6 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
const error = hashParams.get('error') || queryParams.get('error');
|
const error = hashParams.get('error') || queryParams.get('error');
|
||||||
const iss = hashParams.get('iss') || queryParams.get('iss');
|
const iss = hashParams.get('iss') || queryParams.get('iss');
|
||||||
|
|
||||||
console.log('OAuth callback parameters:', {
|
|
||||||
code: code ? code.substring(0, 20) + '...' : null,
|
|
||||||
state: state,
|
|
||||||
error: error,
|
|
||||||
iss: iss,
|
|
||||||
hash: window.location.hash,
|
|
||||||
search: window.location.search
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(`OAuth error: ${error}`);
|
throw new Error(`OAuth error: ${error}`);
|
||||||
@@ -52,12 +40,10 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
throw new Error('Missing OAuth parameters');
|
throw new Error('Missing OAuth parameters');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Processing OAuth callback with params:', { code: code?.substring(0, 10) + '...', state, iss });
|
|
||||||
|
|
||||||
// Use the official BrowserOAuthClient to handle the callback
|
// Use the official BrowserOAuthClient to handle the callback
|
||||||
const result = await atprotoOAuthService.handleOAuthCallback();
|
const result = await atprotoOAuthService.handleOAuthCallback();
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log('OAuth callback completed successfully:', result);
|
|
||||||
|
|
||||||
// Success - notify parent component
|
// Success - notify parent component
|
||||||
onSuccess(result.did, result.handle);
|
onSuccess(result.did, result.handle);
|
||||||
@@ -66,11 +52,7 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('OAuth callback error:', error);
|
|
||||||
|
|
||||||
// Even if OAuth fails, try to continue with a fallback approach
|
// Even if OAuth fails, try to continue with a fallback approach
|
||||||
console.warn('OAuth callback failed, attempting fallback...');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create a minimal session to allow the user to proceed
|
// Create a minimal session to allow the user to proceed
|
||||||
const fallbackSession = {
|
const fallbackSession = {
|
||||||
@@ -82,7 +64,6 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
onSuccess(fallbackSession.did, fallbackSession.handle);
|
onSuccess(fallbackSession.did, fallbackSession.handle);
|
||||||
|
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
console.error('Fallback also failed:', fallbackError);
|
|
||||||
onError(error instanceof Error ? error.message : 'OAuth認証に失敗しました');
|
onError(error instanceof Error ? error.message : 'OAuth認証に失敗しました');
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -104,17 +85,13 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
|
|
||||||
const trimmedHandle = handle.trim();
|
const trimmedHandle = handle.trim();
|
||||||
if (!trimmedHandle) {
|
if (!trimmedHandle) {
|
||||||
console.log('Handle is empty');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Submitting handle:', trimmedHandle);
|
|
||||||
setIsProcessing(true);
|
setIsProcessing(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Resolve DID from handle
|
// Resolve DID from handle
|
||||||
const did = await atprotoOAuthService.resolveDIDFromHandle(trimmedHandle);
|
const did = await atprotoOAuthService.resolveDIDFromHandle(trimmedHandle);
|
||||||
console.log('Resolved DID:', did);
|
|
||||||
|
|
||||||
// Update session with resolved DID and handle
|
// Update session with resolved DID and handle
|
||||||
const updatedSession = {
|
const updatedSession = {
|
||||||
@@ -129,7 +106,6 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
// Success - notify parent component
|
// Success - notify parent component
|
||||||
onSuccess(did, trimmedHandle);
|
onSuccess(did, trimmedHandle);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to resolve DID:', error);
|
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
onError(error instanceof Error ? error.message : 'ハンドルからDIDの解決に失敗しました');
|
onError(error instanceof Error ? error.message : 'ハンドルからDIDの解決に失敗しました');
|
||||||
}
|
}
|
||||||
@@ -149,7 +125,6 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
type="text"
|
type="text"
|
||||||
value={handle}
|
value={handle}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
console.log('Input changed:', e.target.value);
|
|
||||||
setHandle(e.target.value);
|
setHandle(e.target.value);
|
||||||
}}
|
}}
|
||||||
placeholder="例: syui.ai または user.bsky.social"
|
placeholder="例: syui.ai または user.bsky.social"
|
@@ -6,14 +6,9 @@ export const OAuthCallbackPage: React.FC = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('=== OAUTH CALLBACK PAGE MOUNTED ===');
|
|
||||||
console.log('Current URL:', window.location.href);
|
|
||||||
console.log('Search params:', window.location.search);
|
|
||||||
console.log('Pathname:', window.location.pathname);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSuccess = (did: string, handle: string) => {
|
const handleSuccess = (did: string, handle: string) => {
|
||||||
console.log('OAuth success, redirecting to home:', { did, handle });
|
|
||||||
|
|
||||||
// Add a small delay to ensure state is properly updated
|
// Add a small delay to ensure state is properly updated
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -22,7 +17,6 @@ export const OAuthCallbackPage: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleError = (error: string) => {
|
const handleError = (error: string) => {
|
||||||
console.error('OAuth error, redirecting to home:', error);
|
|
||||||
|
|
||||||
// Add a small delay before redirect
|
// Add a small delay before redirect
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
158
oauth/src/config/app.ts
Normal file
158
oauth/src/config/app.ts
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
// Application configuration
|
||||||
|
export interface AppConfig {
|
||||||
|
adminDid: string;
|
||||||
|
adminHandle: string;
|
||||||
|
aiDid: string;
|
||||||
|
aiHandle: string;
|
||||||
|
aiDisplayName: string;
|
||||||
|
aiAvatar: string;
|
||||||
|
aiDescription: string;
|
||||||
|
collections: {
|
||||||
|
base: string; // Base collection like "ai.syui.log"
|
||||||
|
};
|
||||||
|
host: string;
|
||||||
|
rkey?: string; // Current post rkey if on post page
|
||||||
|
aiEnabled: boolean;
|
||||||
|
aiAskAi: boolean;
|
||||||
|
aiProvider: string;
|
||||||
|
aiModel: string;
|
||||||
|
aiHost: string;
|
||||||
|
aiSystemPrompt: string;
|
||||||
|
allowedHandles: string[]; // Handles allowed for OAuth authentication
|
||||||
|
atprotoPds: string; // Configured PDS for admin/ai handles
|
||||||
|
// Legacy - prefer per-user PDS detection
|
||||||
|
bskyPublicApi: string;
|
||||||
|
atprotoApi: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collection name builders (similar to Rust implementation)
|
||||||
|
export function getCollectionNames(base: string) {
|
||||||
|
if (!base) {
|
||||||
|
// Fallback to default
|
||||||
|
base = 'ai.syui.log';
|
||||||
|
}
|
||||||
|
|
||||||
|
const collections = {
|
||||||
|
comment: base,
|
||||||
|
user: `${base}.user`,
|
||||||
|
chat: `${base}.chat`,
|
||||||
|
chatLang: `${base}.chat.lang`,
|
||||||
|
chatComment: `${base}.chat.comment`,
|
||||||
|
};
|
||||||
|
|
||||||
|
return collections;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate collection names from host
|
||||||
|
// Format: ${reg}.${name}.${sub}
|
||||||
|
// Example: log.syui.ai -> ai.syui.log
|
||||||
|
function generateBaseCollectionFromHost(host: string): string {
|
||||||
|
try {
|
||||||
|
// Remove protocol if present
|
||||||
|
const cleanHost = host.replace(/^https?:\/\//, '');
|
||||||
|
|
||||||
|
// Split host into parts
|
||||||
|
const parts = cleanHost.split('.');
|
||||||
|
|
||||||
|
if (parts.length < 2) {
|
||||||
|
throw new Error('Invalid host format');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse the parts for collection naming
|
||||||
|
// log.syui.ai -> ai.syui.log
|
||||||
|
const reversedParts = parts.reverse();
|
||||||
|
const result = reversedParts.join('.');
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
// Fallback to default
|
||||||
|
return 'ai.syui.log';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract rkey from current URL
|
||||||
|
// /posts/xxx -> xxx (remove .html if present)
|
||||||
|
function extractRkeyFromUrl(): string | undefined {
|
||||||
|
const pathname = window.location.pathname;
|
||||||
|
const match = pathname.match(/\/posts\/([^/]+)\/?$/);
|
||||||
|
if (match) {
|
||||||
|
// Remove .html extension if present
|
||||||
|
return match[1].replace(/\.html$/, '');
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get application configuration from environment variables
|
||||||
|
export function getAppConfig(): AppConfig {
|
||||||
|
const host = import.meta.env.VITE_APP_HOST || 'https://log.syui.ai';
|
||||||
|
const adminHandle = import.meta.env.VITE_ADMIN_HANDLE || 'ai.syui.ai';
|
||||||
|
const aiHandle = import.meta.env.VITE_AI_HANDLE || 'ai.syui.ai';
|
||||||
|
|
||||||
|
// DIDsはハンドルから実行時に解決される(フォールバック用のみ保持)
|
||||||
|
const adminDid = import.meta.env.VITE_ADMIN_DID || 'did:plc:uqzpqmrjnptsxezjx4xuh2mn';
|
||||||
|
const aiDid = import.meta.env.VITE_AI_DID || 'did:plc:6qyecktefllvenje24fcxnie';
|
||||||
|
const aiDisplayName = import.meta.env.VITE_AI_DISPLAY_NAME || 'ai';
|
||||||
|
const aiAvatar = import.meta.env.VITE_AI_AVATAR || '';
|
||||||
|
const aiDescription = import.meta.env.VITE_AI_DESCRIPTION || '';
|
||||||
|
|
||||||
|
// Priority: Environment variables > Auto-generated from host
|
||||||
|
const autoGeneratedBase = generateBaseCollectionFromHost(host);
|
||||||
|
let baseCollection = import.meta.env.VITE_OAUTH_COLLECTION || autoGeneratedBase;
|
||||||
|
|
||||||
|
// Ensure base collection is never undefined
|
||||||
|
if (!baseCollection) {
|
||||||
|
baseCollection = 'ai.syui.log';
|
||||||
|
}
|
||||||
|
|
||||||
|
const collections = {
|
||||||
|
base: baseCollection,
|
||||||
|
};
|
||||||
|
|
||||||
|
const rkey = extractRkeyFromUrl();
|
||||||
|
|
||||||
|
// AI configuration
|
||||||
|
const aiEnabled = import.meta.env.VITE_AI_ENABLED === 'true';
|
||||||
|
const aiAskAi = import.meta.env.VITE_AI_ASK_AI === 'true';
|
||||||
|
const aiProvider = import.meta.env.VITE_AI_PROVIDER || 'ollama';
|
||||||
|
const aiModel = import.meta.env.VITE_AI_MODEL || 'gemma3:4b';
|
||||||
|
const aiHost = import.meta.env.VITE_AI_HOST || 'https://ollama.syui.ai';
|
||||||
|
const aiSystemPrompt = import.meta.env.VITE_AI_SYSTEM_PROMPT || 'You are a helpful AI assistant trained on this blog\'s content.';
|
||||||
|
const atprotoPds = import.meta.env.VITE_ATPROTO_PDS || 'syu.is';
|
||||||
|
const bskyPublicApi = import.meta.env.VITE_BSKY_PUBLIC_API || 'https://public.api.bsky.app';
|
||||||
|
const atprotoApi = import.meta.env.VITE_ATPROTO_API || 'https://bsky.social';
|
||||||
|
|
||||||
|
// Parse allowed handles list
|
||||||
|
const allowedHandlesStr = import.meta.env.VITE_ATPROTO_HANDLE_LIST || '[]';
|
||||||
|
let allowedHandles: string[] = [];
|
||||||
|
try {
|
||||||
|
allowedHandles = JSON.parse(allowedHandlesStr);
|
||||||
|
} catch {
|
||||||
|
// If parsing fails, allow all handles (empty array means no restriction)
|
||||||
|
allowedHandles = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
adminDid,
|
||||||
|
adminHandle,
|
||||||
|
aiDid,
|
||||||
|
aiHandle,
|
||||||
|
aiDisplayName,
|
||||||
|
aiAvatar,
|
||||||
|
aiDescription,
|
||||||
|
collections,
|
||||||
|
host,
|
||||||
|
rkey,
|
||||||
|
aiEnabled,
|
||||||
|
aiAskAi,
|
||||||
|
aiProvider,
|
||||||
|
aiModel,
|
||||||
|
aiHost,
|
||||||
|
aiSystemPrompt,
|
||||||
|
allowedHandles,
|
||||||
|
atprotoPds,
|
||||||
|
bskyPublicApi,
|
||||||
|
atprotoApi
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export singleton instance
|
||||||
|
export const appConfig = getAppConfig();
|
28
oauth/src/main.tsx
Normal file
28
oauth/src/main.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/client'
|
||||||
|
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
||||||
|
import App from './App'
|
||||||
|
import { OAuthCallbackPage } from './components/OAuthCallbackPage'
|
||||||
|
import { CardList } from './components/CardList'
|
||||||
|
import { OAuthEndpointHandler } from './utils/oauth-endpoints'
|
||||||
|
|
||||||
|
// Initialize OAuth endpoint handlers for dynamic client metadata and JWKS
|
||||||
|
// DISABLED: This may interfere with BrowserOAuthClient
|
||||||
|
// OAuthEndpointHandler.init()
|
||||||
|
|
||||||
|
// Mount React app to all comment-atproto divs
|
||||||
|
const mountPoints = document.querySelectorAll('#comment-atproto');
|
||||||
|
|
||||||
|
mountPoints.forEach((mountPoint, index) => {
|
||||||
|
ReactDOM.createRoot(mountPoint as HTMLElement).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<BrowserRouter>
|
||||||
|
<Routes>
|
||||||
|
<Route path="/oauth/callback" element={<OAuthCallbackPage />} />
|
||||||
|
<Route path="/list" element={<CardList />} />
|
||||||
|
<Route path="*" element={<App />} />
|
||||||
|
</Routes>
|
||||||
|
</BrowserRouter>
|
||||||
|
</React.StrictMode>,
|
||||||
|
);
|
||||||
|
});
|
@@ -73,7 +73,6 @@ export const aiCardApi = {
|
|||||||
});
|
});
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('ai.gpt AI分析機能が利用できません:', error);
|
|
||||||
throw new Error('AI分析機能を利用するにはai.gptサーバーが必要です');
|
throw new Error('AI分析機能を利用するにはai.gptサーバーが必要です');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -86,7 +85,6 @@ export const aiCardApi = {
|
|||||||
const response = await aiGptApi.get('/card_get_gacha_stats');
|
const response = await aiGptApi.get('/card_get_gacha_stats');
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('ai.gpt AI統計機能が利用できません:', error);
|
|
||||||
throw new Error('AI統計機能を利用するにはai.gptサーバーが必要です');
|
throw new Error('AI統計機能を利用するにはai.gptサーバーが必要です');
|
||||||
}
|
}
|
||||||
},
|
},
|
@@ -12,6 +12,7 @@ interface AtprotoSession {
|
|||||||
|
|
||||||
class AtprotoOAuthService {
|
class AtprotoOAuthService {
|
||||||
private oauthClient: BrowserOAuthClient | null = null;
|
private oauthClient: BrowserOAuthClient | null = null;
|
||||||
|
private oauthClientSyuIs: BrowserOAuthClient | null = null;
|
||||||
private agent: Agent | null = null;
|
private agent: Agent | null = null;
|
||||||
private initializePromise: Promise<void> | null = null;
|
private initializePromise: Promise<void> | null = null;
|
||||||
|
|
||||||
@@ -31,51 +32,50 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
private async _doInitialize(): Promise<void> {
|
private async _doInitialize(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('=== INITIALIZING ATPROTO OAUTH CLIENT ===');
|
|
||||||
|
|
||||||
// Generate client ID based on current origin
|
// Generate client ID based on current origin
|
||||||
const clientId = this.getClientId();
|
const clientId = this.getClientId();
|
||||||
console.log('Client ID:', clientId);
|
|
||||||
|
// Initialize both OAuth clients
|
||||||
// Support multiple PDS hosts for OAuth
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
handleResolver: 'https://bsky.social', // Default resolver
|
handleResolver: 'https://bsky.social',
|
||||||
|
plcDirectoryUrl: 'https://plc.directory',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.oauthClientSyuIs = await BrowserOAuthClient.load({
|
||||||
|
clientId: clientId,
|
||||||
|
handleResolver: 'https://syu.is',
|
||||||
|
plcDirectoryUrl: 'https://plc.syu.is',
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('BrowserOAuthClient initialized successfully with multi-PDS support');
|
// Try to restore existing session from either client
|
||||||
|
let result = await this.oauthClient.init();
|
||||||
// Try to restore existing session
|
if (!result?.session) {
|
||||||
const result = await this.oauthClient.init();
|
result = await this.oauthClientSyuIs.init();
|
||||||
|
}
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
console.log('Existing session restored:', {
|
|
||||||
did: result.session.did,
|
|
||||||
handle: result.session.handle || 'unknown',
|
|
||||||
hasAccessJwt: !!result.session.accessJwt,
|
|
||||||
hasRefreshJwt: !!result.session.refreshJwt
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create Agent instance with proper configuration
|
// Create Agent instance with proper configuration
|
||||||
console.log('Creating Agent with session:', result.session);
|
|
||||||
|
|
||||||
// Delete the old agent initialization code - we'll create it properly below
|
// Delete the old agent initialization code - we'll create it properly below
|
||||||
|
|
||||||
// Set the session after creating the agent
|
// Set the session after creating the agent
|
||||||
// The session object from BrowserOAuthClient appears to be a special object
|
// The session object from BrowserOAuthClient appears to be a special object
|
||||||
console.log('Full session object:', result.session);
|
|
||||||
console.log('Session type:', typeof result.session);
|
|
||||||
console.log('Session constructor:', result.session?.constructor?.name);
|
|
||||||
|
|
||||||
// Try to iterate over the session object
|
// Try to iterate over the session object
|
||||||
if (result.session) {
|
if (result.session) {
|
||||||
console.log('Session properties:');
|
|
||||||
for (const key in result.session) {
|
for (const key in result.session) {
|
||||||
console.log(` ${key}:`, result.session[key]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if session has methods
|
// Check if session has methods
|
||||||
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(result.session));
|
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(result.session));
|
||||||
console.log('Session methods:', methods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BrowserOAuthClient might return a Session object that needs to be used with the agent
|
// BrowserOAuthClient might return a Session object that needs to be used with the agent
|
||||||
@@ -83,56 +83,28 @@ class AtprotoOAuthService {
|
|||||||
if (result.session) {
|
if (result.session) {
|
||||||
// Process the session to extract DID and handle
|
// Process the session to extract DID and handle
|
||||||
const sessionData = await this.processSession(result.session);
|
const sessionData = await this.processSession(result.session);
|
||||||
console.log('Session processed during initialization:', sessionData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log('No existing session found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize OAuth client:', error);
|
|
||||||
this.initializePromise = null; // Reset on error to allow retry
|
this.initializePromise = null; // Reset on error to allow retry
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processSession(session: any): Promise<{ did: string; handle: string }> {
|
private async processSession(session: any): Promise<{ did: string; handle: string }> {
|
||||||
console.log('Processing session:', session);
|
|
||||||
|
|
||||||
// Log full session structure
|
|
||||||
console.log('Session structure:');
|
|
||||||
console.log('- sub:', session.sub);
|
|
||||||
console.log('- did:', session.did);
|
|
||||||
console.log('- handle:', session.handle);
|
|
||||||
console.log('- iss:', session.iss);
|
|
||||||
console.log('- aud:', session.aud);
|
|
||||||
|
|
||||||
// Check if agent has properties we can access
|
|
||||||
if (session.agent) {
|
|
||||||
console.log('- agent:', session.agent);
|
|
||||||
console.log('- agent.did:', session.agent?.did);
|
|
||||||
console.log('- agent.handle:', session.agent?.handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
const did = session.sub || session.did;
|
const did = session.sub || session.did;
|
||||||
let handle = session.handle || 'unknown';
|
let handle = session.handle || 'unknown';
|
||||||
|
|
||||||
// Create Agent directly with session (per official docs)
|
// Create Agent directly with session (per official docs)
|
||||||
try {
|
try {
|
||||||
this.agent = new Agent(session);
|
this.agent = new Agent(session);
|
||||||
console.log('Agent created directly with session');
|
|
||||||
|
|
||||||
// Check if agent has session info after creation
|
|
||||||
console.log('Agent after creation:');
|
|
||||||
console.log('- agent.did:', this.agent.did);
|
|
||||||
console.log('- agent.session:', this.agent.session);
|
|
||||||
if (this.agent.session) {
|
|
||||||
console.log('- agent.session.did:', this.agent.session.did);
|
|
||||||
console.log('- agent.session.handle:', this.agent.session.handle);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Failed to create Agent with session directly, trying dpopFetch method');
|
|
||||||
// Fallback to dpopFetch method
|
// Fallback to dpopFetch method
|
||||||
this.agent = new Agent({
|
this.agent = new Agent({
|
||||||
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
||||||
@@ -145,7 +117,7 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
// If handle is missing, try multiple methods to resolve it
|
// If handle is missing, try multiple methods to resolve it
|
||||||
if (!handle || handle === 'unknown') {
|
if (!handle || handle === 'unknown') {
|
||||||
console.log('Handle not in session, attempting to resolve...');
|
|
||||||
|
|
||||||
// Method 1: Try using the agent to get profile
|
// Method 1: Try using the agent to get profile
|
||||||
try {
|
try {
|
||||||
@@ -154,11 +126,11 @@ class AtprotoOAuthService {
|
|||||||
if (profile.data.handle) {
|
if (profile.data.handle) {
|
||||||
handle = profile.data.handle;
|
handle = profile.data.handle;
|
||||||
(this as any)._sessionInfo.handle = handle;
|
(this as any)._sessionInfo.handle = handle;
|
||||||
console.log('Successfully resolved handle via getProfile:', handle);
|
|
||||||
return { did, handle };
|
return { did, handle };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('getProfile failed:', err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method 2: Try using describeRepo
|
// Method 2: Try using describeRepo
|
||||||
@@ -169,18 +141,20 @@ class AtprotoOAuthService {
|
|||||||
if (repoDesc.data.handle) {
|
if (repoDesc.data.handle) {
|
||||||
handle = repoDesc.data.handle;
|
handle = repoDesc.data.handle;
|
||||||
(this as any)._sessionInfo.handle = handle;
|
(this as any)._sessionInfo.handle = handle;
|
||||||
console.log('Got handle from describeRepo:', handle);
|
|
||||||
return { did, handle };
|
return { did, handle };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('describeRepo failed:', err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method 3: Hardcoded fallback for known DIDs
|
// Method 3: Fallback for admin DID
|
||||||
if (did === 'did:plc:uqzpqmrjnptsxezjx4xuh2mn') {
|
const adminDid = import.meta.env.VITE_ADMIN_DID;
|
||||||
handle = 'syui.ai';
|
if (did === adminDid) {
|
||||||
|
const appHost = import.meta.env.VITE_APP_HOST || 'https://syui.ai';
|
||||||
|
handle = new URL(appHost).hostname;
|
||||||
(this as any)._sessionInfo.handle = handle;
|
(this as any)._sessionInfo.handle = handle;
|
||||||
console.log('Using hardcoded handle for known DID');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +165,7 @@ class AtprotoOAuthService {
|
|||||||
// Use environment variable if available
|
// Use environment variable if available
|
||||||
const envClientId = import.meta.env.VITE_OAUTH_CLIENT_ID;
|
const envClientId = import.meta.env.VITE_OAUTH_CLIENT_ID;
|
||||||
if (envClientId) {
|
if (envClientId) {
|
||||||
console.log('Using client ID from environment:', envClientId);
|
|
||||||
return envClientId;
|
return envClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +174,7 @@ class AtprotoOAuthService {
|
|||||||
// For localhost development, use undefined for loopback client
|
// For localhost development, use undefined for loopback client
|
||||||
// The BrowserOAuthClient will handle this automatically
|
// The BrowserOAuthClient will handle this automatically
|
||||||
if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
|
if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
|
||||||
console.log('Using loopback client for localhost development');
|
|
||||||
return undefined as any; // Loopback client
|
return undefined as any; // Loopback client
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,39 +182,15 @@ class AtprotoOAuthService {
|
|||||||
return `${origin}/client-metadata.json`;
|
return `${origin}/client-metadata.json`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private detectPDSFromHandle(handle: string): string {
|
|
||||||
console.log('Detecting PDS for handle:', handle);
|
|
||||||
|
|
||||||
// Supported PDS hosts and their corresponding handles
|
|
||||||
const pdsMapping = {
|
|
||||||
'syu.is': 'https://syu.is',
|
|
||||||
'bsky.social': 'https://bsky.social',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check if handle ends with known PDS domains
|
|
||||||
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
|
|
||||||
if (handle.endsWith(`.${domain}`)) {
|
|
||||||
console.log(`Handle ${handle} mapped to PDS: ${pdsUrl}`);
|
|
||||||
return pdsUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to bsky.social
|
|
||||||
console.log(`Handle ${handle} using default PDS: https://bsky.social`);
|
|
||||||
return 'https://bsky.social';
|
|
||||||
}
|
|
||||||
|
|
||||||
async initiateOAuthFlow(handle?: string): Promise<void> {
|
async initiateOAuthFlow(handle?: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('=== INITIATING OAUTH FLOW ===');
|
if (!this.oauthClient || !this.oauthClientSyuIs) {
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
|
||||||
console.log('OAuth client not initialized, initializing now...');
|
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient || !this.oauthClientSyuIs) {
|
||||||
throw new Error('Failed to initialize OAuth client');
|
throw new Error('Failed to initialize OAuth clients');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If handle is not provided, prompt user
|
// If handle is not provided, prompt user
|
||||||
@@ -251,75 +201,42 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Starting OAuth flow for handle:', handle);
|
// Determine which OAuth client to use
|
||||||
|
const allowedHandlesStr = import.meta.env.VITE_ATPROTO_HANDLE_LIST || '[]';
|
||||||
// Detect PDS based on handle
|
let allowedHandles: string[] = [];
|
||||||
const pdsUrl = this.detectPDSFromHandle(handle);
|
|
||||||
console.log('Detected PDS for handle:', { handle, pdsUrl });
|
|
||||||
|
|
||||||
// Re-initialize OAuth client with correct PDS if needed
|
|
||||||
if (pdsUrl !== 'https://bsky.social') {
|
|
||||||
console.log('Re-initializing OAuth client for custom PDS:', pdsUrl);
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
|
||||||
clientId: this.getClientId(),
|
|
||||||
handleResolver: pdsUrl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start OAuth authorization flow
|
|
||||||
console.log('Calling oauthClient.authorize with handle:', handle);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const authUrl = await this.oauthClient.authorize(handle, {
|
allowedHandles = JSON.parse(allowedHandlesStr);
|
||||||
scope: 'atproto transition:generic',
|
} catch {
|
||||||
});
|
allowedHandles = [];
|
||||||
|
|
||||||
console.log('Authorization URL generated:', authUrl.toString());
|
|
||||||
console.log('URL breakdown:', {
|
|
||||||
protocol: authUrl.protocol,
|
|
||||||
hostname: authUrl.hostname,
|
|
||||||
pathname: authUrl.pathname,
|
|
||||||
search: authUrl.search
|
|
||||||
});
|
|
||||||
|
|
||||||
// Store some debug info before redirect
|
|
||||||
sessionStorage.setItem('oauth_debug_pre_redirect', JSON.stringify({
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
handle: handle,
|
|
||||||
authUrl: authUrl.toString(),
|
|
||||||
currentUrl: window.location.href
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Redirect to authorization server
|
|
||||||
console.log('About to redirect to:', authUrl.toString());
|
|
||||||
window.location.href = authUrl.toString();
|
|
||||||
} catch (authorizeError) {
|
|
||||||
console.error('oauthClient.authorize failed:', authorizeError);
|
|
||||||
console.error('Error details:', {
|
|
||||||
name: authorizeError.name,
|
|
||||||
message: authorizeError.message,
|
|
||||||
stack: authorizeError.stack
|
|
||||||
});
|
|
||||||
throw authorizeError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const usesSyuIs = handle.endsWith('.syu.is') || allowedHandles.includes(handle);
|
||||||
|
const oauthClient = usesSyuIs ? this.oauthClientSyuIs : this.oauthClient;
|
||||||
|
|
||||||
|
// Start OAuth authorization flow
|
||||||
|
const authUrl = await oauthClient.authorize(handle, {
|
||||||
|
scope: 'atproto transition:generic',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Redirect to authorization server
|
||||||
|
window.location.href = authUrl.toString();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initiate OAuth flow:', error);
|
|
||||||
throw new Error(`OAuth認証の開始に失敗しました: ${error}`);
|
throw new Error(`OAuth認証の開始に失敗しました: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleOAuthCallback(): Promise<{ did: string; handle: string } | null> {
|
async handleOAuthCallback(): Promise<{ did: string; handle: string } | null> {
|
||||||
try {
|
try {
|
||||||
console.log('=== HANDLING OAUTH CALLBACK ===');
|
|
||||||
console.log('Current URL:', window.location.href);
|
|
||||||
console.log('URL hash:', window.location.hash);
|
|
||||||
console.log('URL search:', window.location.search);
|
|
||||||
|
|
||||||
// BrowserOAuthClient should automatically handle the callback
|
// BrowserOAuthClient should automatically handle the callback
|
||||||
// We just need to initialize it and it will process the current URL
|
// We just need to initialize it and it will process the current URL
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
console.log('OAuth client not initialized, initializing now...');
|
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,11 +244,11 @@ class AtprotoOAuthService {
|
|||||||
throw new Error('Failed to initialize OAuth client');
|
throw new Error('Failed to initialize OAuth client');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('OAuth client ready, initializing to process callback...');
|
|
||||||
|
|
||||||
// Call init() again to process the callback URL
|
// Call init() again to process the callback URL
|
||||||
const result = await this.oauthClient.init();
|
const result = await this.oauthClient.init();
|
||||||
console.log('OAuth callback processing result:', result);
|
|
||||||
|
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
// Process the session
|
// Process the session
|
||||||
@@ -339,47 +256,36 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If no session yet, wait a bit and try again
|
// If no session yet, wait a bit and try again
|
||||||
console.log('No session found immediately, waiting...');
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
// Try to check session again
|
// Try to check session again
|
||||||
const sessionCheck = await this.checkSession();
|
const sessionCheck = await this.checkSession();
|
||||||
if (sessionCheck) {
|
if (sessionCheck) {
|
||||||
console.log('Session found after delay:', sessionCheck);
|
|
||||||
return sessionCheck;
|
return sessionCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn('OAuth callback completed but no session was created');
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('OAuth callback handling failed:', error);
|
|
||||||
console.error('Error details:', {
|
|
||||||
name: error.name,
|
|
||||||
message: error.message,
|
|
||||||
stack: error.stack
|
|
||||||
});
|
|
||||||
throw new Error(`OAuth認証の完了に失敗しました: ${error.message}`);
|
throw new Error(`OAuth認証の完了に失敗しました: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkSession(): Promise<{ did: string; handle: string } | null> {
|
async checkSession(): Promise<{ did: string; handle: string } | null> {
|
||||||
try {
|
try {
|
||||||
console.log('=== CHECK SESSION CALLED ===');
|
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
console.log('No OAuth client, initializing...');
|
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
console.log('OAuth client initialization failed');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Running oauthClient.init() to check session...');
|
|
||||||
const result = await this.oauthClient.init();
|
const result = await this.oauthClient.init();
|
||||||
console.log('oauthClient.init() result:', result);
|
|
||||||
|
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
// Use the common session processing method
|
// Use the common session processing method
|
||||||
@@ -388,7 +294,7 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Session check failed:', error);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,13 +304,7 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSession(): AtprotoSession | null {
|
getSession(): AtprotoSession | null {
|
||||||
console.log('getSession called');
|
|
||||||
console.log('Current state:', {
|
|
||||||
hasAgent: !!this.agent,
|
|
||||||
hasAgentSession: !!this.agent?.session,
|
|
||||||
hasOAuthClient: !!this.oauthClient,
|
|
||||||
hasSessionInfo: !!(this as any)._sessionInfo
|
|
||||||
});
|
|
||||||
|
|
||||||
// First check if we have an agent with session
|
// First check if we have an agent with session
|
||||||
if (this.agent?.session) {
|
if (this.agent?.session) {
|
||||||
@@ -414,7 +314,7 @@ class AtprotoOAuthService {
|
|||||||
accessJwt: this.agent.session.accessJwt || '',
|
accessJwt: this.agent.session.accessJwt || '',
|
||||||
refreshJwt: this.agent.session.refreshJwt || '',
|
refreshJwt: this.agent.session.refreshJwt || '',
|
||||||
};
|
};
|
||||||
console.log('Returning agent session:', session);
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,11 +326,11 @@ class AtprotoOAuthService {
|
|||||||
accessJwt: 'dpop-protected', // Indicate that tokens are handled by dpopFetch
|
accessJwt: 'dpop-protected', // Indicate that tokens are handled by dpopFetch
|
||||||
refreshJwt: 'dpop-protected',
|
refreshJwt: 'dpop-protected',
|
||||||
};
|
};
|
||||||
console.log('Returning stored session info:', session);
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('No session available');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,28 +350,20 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
async logout(): Promise<void> {
|
async logout(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('=== LOGGING OUT ===');
|
|
||||||
|
|
||||||
// Clear Agent
|
// Clear Agent
|
||||||
this.agent = null;
|
this.agent = null;
|
||||||
console.log('Agent cleared');
|
|
||||||
|
|
||||||
// Clear BrowserOAuthClient session
|
// Clear BrowserOAuthClient session
|
||||||
if (this.oauthClient) {
|
if (this.oauthClient) {
|
||||||
console.log('Clearing OAuth client session...');
|
|
||||||
try {
|
try {
|
||||||
// BrowserOAuthClient may have a revoke or signOut method
|
// BrowserOAuthClient may have a revoke or signOut method
|
||||||
if (typeof (this.oauthClient as any).signOut === 'function') {
|
if (typeof (this.oauthClient as any).signOut === 'function') {
|
||||||
await (this.oauthClient as any).signOut();
|
await (this.oauthClient as any).signOut();
|
||||||
console.log('OAuth client signed out');
|
|
||||||
} else if (typeof (this.oauthClient as any).revoke === 'function') {
|
} else if (typeof (this.oauthClient as any).revoke === 'function') {
|
||||||
await (this.oauthClient as any).revoke();
|
await (this.oauthClient as any).revoke();
|
||||||
console.log('OAuth client revoked');
|
|
||||||
} else {
|
|
||||||
console.log('No explicit signOut method found on OAuth client');
|
|
||||||
}
|
}
|
||||||
} catch (oauthError) {
|
} catch (oauthError) {
|
||||||
console.error('OAuth client logout error:', oauthError);
|
// Ignore logout errors
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the OAuth client to force re-initialization
|
// Reset the OAuth client to force re-initialization
|
||||||
@@ -483,20 +375,18 @@ class AtprotoOAuthService {
|
|||||||
localStorage.removeItem('atproto_session');
|
localStorage.removeItem('atproto_session');
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
// Clear all localStorage items that might be related to OAuth
|
// Clear all OAuth-related storage
|
||||||
const keysToRemove: string[] = [];
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) {
|
if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) {
|
||||||
keysToRemove.push(key);
|
localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keysToRemove.forEach(key => {
|
|
||||||
console.log('Removing localStorage key:', key);
|
|
||||||
localStorage.removeItem(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('=== LOGOUT COMPLETED ===');
|
// Clear internal session info
|
||||||
|
(this as any)._sessionInfo = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Force page reload to ensure clean state
|
// Force page reload to ensure clean state
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -504,7 +394,7 @@ class AtprotoOAuthService {
|
|||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Logout failed:', error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,8 +409,8 @@ class AtprotoOAuthService {
|
|||||||
const did = sessionInfo.did;
|
const did = sessionInfo.did;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Saving cards to atproto collection...');
|
|
||||||
console.log('Using DID:', did);
|
|
||||||
|
|
||||||
// Ensure we have a fresh agent
|
// Ensure we have a fresh agent
|
||||||
if (!this.agent) {
|
if (!this.agent) {
|
||||||
@@ -550,13 +440,6 @@ class AtprotoOAuthService {
|
|||||||
createdAt: createdAt
|
createdAt: createdAt
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('PutRecord request:', {
|
|
||||||
repo: did,
|
|
||||||
collection: collection,
|
|
||||||
rkey: rkey,
|
|
||||||
record: record
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Use Agent's com.atproto.repo.putRecord method
|
// Use Agent's com.atproto.repo.putRecord method
|
||||||
const response = await this.agent.com.atproto.repo.putRecord({
|
const response = await this.agent.com.atproto.repo.putRecord({
|
||||||
@@ -566,9 +449,9 @@ class AtprotoOAuthService {
|
|||||||
record: record
|
record: record
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('カードデータをai.card.boxに保存しました:', response);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('カードボックス保存エラー:', error);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -584,8 +467,8 @@ class AtprotoOAuthService {
|
|||||||
const did = sessionInfo.did;
|
const did = sessionInfo.did;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Fetching cards from atproto collection...');
|
|
||||||
console.log('Using DID:', did);
|
|
||||||
|
|
||||||
// Ensure we have a fresh agent
|
// Ensure we have a fresh agent
|
||||||
if (!this.agent) {
|
if (!this.agent) {
|
||||||
@@ -598,7 +481,7 @@ class AtprotoOAuthService {
|
|||||||
rkey: 'self'
|
rkey: 'self'
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Cards from box response:', response);
|
|
||||||
|
|
||||||
// Convert to expected format
|
// Convert to expected format
|
||||||
const result = {
|
const result = {
|
||||||
@@ -611,7 +494,7 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('カードボックス取得エラー:', error);
|
|
||||||
|
|
||||||
// If record doesn't exist, return empty
|
// If record doesn't exist, return empty
|
||||||
if (error.toString().includes('RecordNotFound')) {
|
if (error.toString().includes('RecordNotFound')) {
|
||||||
@@ -633,8 +516,8 @@ class AtprotoOAuthService {
|
|||||||
const did = sessionInfo.did;
|
const did = sessionInfo.did;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Deleting card box collection...');
|
|
||||||
console.log('Using DID:', did);
|
|
||||||
|
|
||||||
// Ensure we have a fresh agent
|
// Ensure we have a fresh agent
|
||||||
if (!this.agent) {
|
if (!this.agent) {
|
||||||
@@ -647,33 +530,35 @@ class AtprotoOAuthService {
|
|||||||
rkey: 'self'
|
rkey: 'self'
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Card box deleted successfully:', response);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('カードボックス削除エラー:', error);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手動でトークンを設定(開発・デバッグ用)
|
// 手動でトークンを設定(開発・デバッグ用)
|
||||||
setManualTokens(accessJwt: string, refreshJwt: string): void {
|
setManualTokens(accessJwt: string, refreshJwt: string): void {
|
||||||
console.warn('Manual token setting is not supported with official BrowserOAuthClient');
|
|
||||||
console.warn('Please use the proper OAuth flow instead');
|
|
||||||
|
|
||||||
// For backward compatibility, store in localStorage
|
// For backward compatibility, store in localStorage
|
||||||
|
const adminDid = import.meta.env.VITE_ADMIN_DID || 'did:plc:unknown';
|
||||||
|
const appHost = import.meta.env.VITE_APP_HOST || 'https://example.com';
|
||||||
const session: AtprotoSession = {
|
const session: AtprotoSession = {
|
||||||
did: 'did:plc:uqzpqmrjnptsxezjx4xuh2mn',
|
did: adminDid,
|
||||||
handle: 'syui.ai',
|
handle: new URL(appHost).hostname,
|
||||||
accessJwt: accessJwt,
|
accessJwt: accessJwt,
|
||||||
refreshJwt: refreshJwt
|
refreshJwt: refreshJwt
|
||||||
};
|
};
|
||||||
|
|
||||||
localStorage.setItem('atproto_session', JSON.stringify(session));
|
localStorage.setItem('atproto_session', JSON.stringify(session));
|
||||||
console.log('Manual tokens stored in localStorage for backward compatibility');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 後方互換性のための従来関数
|
// 後方互換性のための従来関数
|
||||||
saveSessionToStorage(session: AtprotoSession): void {
|
saveSessionToStorage(session: AtprotoSession): void {
|
||||||
console.warn('saveSessionToStorage is deprecated with BrowserOAuthClient');
|
|
||||||
localStorage.setItem('atproto_session', JSON.stringify(session));
|
localStorage.setItem('atproto_session', JSON.stringify(session));
|
||||||
}
|
}
|
||||||
|
|
135
oauth/src/tests/console-test.ts
Normal file
135
oauth/src/tests/console-test.ts
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
// Simple console test for OAuth app
|
||||||
|
// This runs before 'npm run preview' to display test results
|
||||||
|
|
||||||
|
// Mock import.meta.env for Node.js environment
|
||||||
|
(global as any).import = {
|
||||||
|
meta: {
|
||||||
|
env: {
|
||||||
|
VITE_ATPROTO_PDS: process.env.VITE_ATPROTO_PDS || 'syu.is',
|
||||||
|
VITE_ADMIN_HANDLE: process.env.VITE_ADMIN_HANDLE || 'ai.syui.ai',
|
||||||
|
VITE_AI_HANDLE: process.env.VITE_AI_HANDLE || 'ai.syui.ai',
|
||||||
|
VITE_OAUTH_COLLECTION: process.env.VITE_OAUTH_COLLECTION || 'ai.syui.log',
|
||||||
|
VITE_ATPROTO_HANDLE_LIST: process.env.VITE_ATPROTO_HANDLE_LIST || '["syui.ai", "ai.syui.ai", "yui.syui.ai"]',
|
||||||
|
VITE_APP_HOST: process.env.VITE_APP_HOST || 'https://log.syui.ai'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Simple implementation of functions for testing
|
||||||
|
function detectPdsFromHandle(handle: string): string {
|
||||||
|
if (handle.endsWith('.syu.is') || handle.endsWith('.syui.ai')) {
|
||||||
|
return 'syu.is';
|
||||||
|
}
|
||||||
|
if (handle.endsWith('.bsky.social')) {
|
||||||
|
return 'bsky.social';
|
||||||
|
}
|
||||||
|
// Default case - check if it's in the allowed list
|
||||||
|
const allowedHandles = JSON.parse((global as any).import.meta.env.VITE_ATPROTO_HANDLE_LIST || '[]');
|
||||||
|
if (allowedHandles.includes(handle)) {
|
||||||
|
return (global as any).import.meta.env.VITE_ATPROTO_PDS || 'syu.is';
|
||||||
|
}
|
||||||
|
return 'bsky.social';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNetworkConfig(pds: string) {
|
||||||
|
switch (pds) {
|
||||||
|
case 'bsky.social':
|
||||||
|
case 'bsky.app':
|
||||||
|
return {
|
||||||
|
pdsApi: `https://${pds}`,
|
||||||
|
plcApi: 'https://plc.directory',
|
||||||
|
bskyApi: 'https://public.api.bsky.app',
|
||||||
|
webUrl: 'https://bsky.app'
|
||||||
|
};
|
||||||
|
case 'syu.is':
|
||||||
|
return {
|
||||||
|
pdsApi: 'https://syu.is',
|
||||||
|
plcApi: 'https://plc.syu.is',
|
||||||
|
bskyApi: 'https://bsky.syu.is',
|
||||||
|
webUrl: 'https://web.syu.is'
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
pdsApi: `https://${pds}`,
|
||||||
|
plcApi: 'https://plc.directory',
|
||||||
|
bskyApi: 'https://public.api.bsky.app',
|
||||||
|
webUrl: 'https://bsky.app'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main test execution
|
||||||
|
console.log('\n=== OAuth App Configuration Tests ===\n');
|
||||||
|
|
||||||
|
// Test 1: Handle input behavior
|
||||||
|
console.log('1. Handle Input → PDS Detection:');
|
||||||
|
const testHandles = [
|
||||||
|
'syui.ai',
|
||||||
|
'syui.syu.is',
|
||||||
|
'syui.syui.ai',
|
||||||
|
'test.bsky.social',
|
||||||
|
'unknown.handle'
|
||||||
|
];
|
||||||
|
|
||||||
|
testHandles.forEach(handle => {
|
||||||
|
const pds = detectPdsFromHandle(handle);
|
||||||
|
const config = getNetworkConfig(pds);
|
||||||
|
console.log(` ${handle.padEnd(20)} → PDS: ${pds.padEnd(12)} → API: ${config.pdsApi}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test 2: Environment variable impact
|
||||||
|
console.log('\n2. Current Environment Configuration:');
|
||||||
|
const env = (global as any).import.meta.env;
|
||||||
|
console.log(` VITE_ATPROTO_PDS: ${env.VITE_ATPROTO_PDS}`);
|
||||||
|
console.log(` VITE_ADMIN_HANDLE: ${env.VITE_ADMIN_HANDLE}`);
|
||||||
|
console.log(` VITE_AI_HANDLE: ${env.VITE_AI_HANDLE}`);
|
||||||
|
console.log(` VITE_OAUTH_COLLECTION: ${env.VITE_OAUTH_COLLECTION}`);
|
||||||
|
console.log(` VITE_ATPROTO_HANDLE_LIST: ${env.VITE_ATPROTO_HANDLE_LIST}`);
|
||||||
|
|
||||||
|
// Test 3: API endpoint generation
|
||||||
|
console.log('\n3. Generated API Endpoints:');
|
||||||
|
const adminPds = detectPdsFromHandle(env.VITE_ADMIN_HANDLE);
|
||||||
|
const adminConfig = getNetworkConfig(adminPds);
|
||||||
|
console.log(` Admin PDS detection: ${env.VITE_ADMIN_HANDLE} → ${adminPds}`);
|
||||||
|
console.log(` Admin API endpoints:`);
|
||||||
|
console.log(` - PDS API: ${adminConfig.pdsApi}`);
|
||||||
|
console.log(` - Bsky API: ${adminConfig.bskyApi}`);
|
||||||
|
console.log(` - Web URL: ${adminConfig.webUrl}`);
|
||||||
|
|
||||||
|
// Test 4: Collection URLs
|
||||||
|
console.log('\n4. Collection API URLs:');
|
||||||
|
const baseCollection = env.VITE_OAUTH_COLLECTION;
|
||||||
|
console.log(` User list: ${adminConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${env.VITE_ADMIN_HANDLE}&collection=${baseCollection}.user`);
|
||||||
|
console.log(` Chat: ${adminConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${env.VITE_ADMIN_HANDLE}&collection=${baseCollection}.chat`);
|
||||||
|
console.log(` Lang: ${adminConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${env.VITE_ADMIN_HANDLE}&collection=${baseCollection}.chat.lang`);
|
||||||
|
console.log(` Comment: ${adminConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${env.VITE_ADMIN_HANDLE}&collection=${baseCollection}.chat.comment`);
|
||||||
|
|
||||||
|
// Test 5: OAuth routing logic
|
||||||
|
console.log('\n5. OAuth Authorization Logic:');
|
||||||
|
const allowedHandles = JSON.parse(env.VITE_ATPROTO_HANDLE_LIST || '[]');
|
||||||
|
console.log(` Allowed handles: ${JSON.stringify(allowedHandles)}`);
|
||||||
|
console.log(` OAuth scenarios:`);
|
||||||
|
|
||||||
|
const oauthTestCases = [
|
||||||
|
'syui.ai', // Should use syu.is (in allowed list)
|
||||||
|
'test.syu.is', // Should use syu.is (*.syu.is pattern)
|
||||||
|
'user.bsky.social' // Should use bsky.social (default)
|
||||||
|
];
|
||||||
|
|
||||||
|
oauthTestCases.forEach(handle => {
|
||||||
|
const pds = detectPdsFromHandle(handle);
|
||||||
|
const isAllowed = allowedHandles.includes(handle);
|
||||||
|
const reason = handle.endsWith('.syu.is') ? '*.syu.is pattern' :
|
||||||
|
isAllowed ? 'in allowed list' :
|
||||||
|
'default';
|
||||||
|
console.log(` ${handle.padEnd(20)} → https://${pds}/oauth/authorize (${reason})`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test 6: AI Profile Resolution
|
||||||
|
console.log('\n6. AI Profile Resolution:');
|
||||||
|
const aiPds = detectPdsFromHandle(env.VITE_AI_HANDLE);
|
||||||
|
const aiConfig = getNetworkConfig(aiPds);
|
||||||
|
console.log(` AI Handle: ${env.VITE_AI_HANDLE} → PDS: ${aiPds}`);
|
||||||
|
console.log(` AI Profile API: ${aiConfig.bskyApi}/xrpc/app.bsky.actor.getProfile?actor=${env.VITE_AI_HANDLE}`);
|
||||||
|
|
||||||
|
console.log('\n=== Tests Complete ===\n');
|
141
oauth/src/tests/oauth.test.ts
Normal file
141
oauth/src/tests/oauth.test.ts
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import { getAppConfig } from '../config/app';
|
||||||
|
import { detectPdsFromHandle, getNetworkConfig } from '../App';
|
||||||
|
|
||||||
|
// Test helper to mock environment variables
|
||||||
|
const mockEnv = (vars: Record<string, string>) => {
|
||||||
|
Object.keys(vars).forEach(key => {
|
||||||
|
(import.meta.env as any)[key] = vars[key];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('OAuth App Tests', () => {
|
||||||
|
describe('Handle Input Behavior', () => {
|
||||||
|
it('should detect PDS for syui.ai (Bluesky)', () => {
|
||||||
|
const pds = detectPdsFromHandle('syui.ai');
|
||||||
|
expect(pds).toBe('bsky.social');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should detect PDS for syui.syu.is (syu.is)', () => {
|
||||||
|
const pds = detectPdsFromHandle('syui.syu.is');
|
||||||
|
expect(pds).toBe('syu.is');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should detect PDS for syui.syui.ai (syu.is)', () => {
|
||||||
|
const pds = detectPdsFromHandle('syui.syui.ai');
|
||||||
|
expect(pds).toBe('syu.is');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use network config for different PDS', () => {
|
||||||
|
const bskyConfig = getNetworkConfig('bsky.social');
|
||||||
|
expect(bskyConfig.pdsApi).toBe('https://bsky.social');
|
||||||
|
expect(bskyConfig.bskyApi).toBe('https://public.api.bsky.app');
|
||||||
|
expect(bskyConfig.webUrl).toBe('https://bsky.app');
|
||||||
|
|
||||||
|
const syuisConfig = getNetworkConfig('syu.is');
|
||||||
|
expect(syuisConfig.pdsApi).toBe('https://syu.is');
|
||||||
|
expect(syuisConfig.bskyApi).toBe('https://bsky.syu.is');
|
||||||
|
expect(syuisConfig.webUrl).toBe('https://web.syu.is');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Environment Variable Changes', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// Reset environment variables
|
||||||
|
delete (import.meta.env as any).VITE_ATPROTO_PDS;
|
||||||
|
delete (import.meta.env as any).VITE_ADMIN_HANDLE;
|
||||||
|
delete (import.meta.env as any).VITE_AI_HANDLE;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use correct PDS for AI profile', () => {
|
||||||
|
mockEnv({
|
||||||
|
VITE_ATPROTO_PDS: 'syu.is',
|
||||||
|
VITE_ADMIN_HANDLE: 'ai.syui.ai',
|
||||||
|
VITE_AI_HANDLE: 'ai.syui.ai'
|
||||||
|
});
|
||||||
|
|
||||||
|
const config = getAppConfig();
|
||||||
|
expect(config.atprotoPds).toBe('syu.is');
|
||||||
|
expect(config.adminHandle).toBe('ai.syui.ai');
|
||||||
|
expect(config.aiHandle).toBe('ai.syui.ai');
|
||||||
|
|
||||||
|
// Network config should use syu.is endpoints
|
||||||
|
const networkConfig = getNetworkConfig(config.atprotoPds);
|
||||||
|
expect(networkConfig.bskyApi).toBe('https://bsky.syu.is');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should construct correct API requests for admin userlist', () => {
|
||||||
|
mockEnv({
|
||||||
|
VITE_ATPROTO_PDS: 'syu.is',
|
||||||
|
VITE_ADMIN_HANDLE: 'ai.syui.ai',
|
||||||
|
VITE_OAUTH_COLLECTION: 'ai.syui.log'
|
||||||
|
});
|
||||||
|
|
||||||
|
const config = getAppConfig();
|
||||||
|
const networkConfig = getNetworkConfig(config.atprotoPds);
|
||||||
|
const userListUrl = `${networkConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${config.adminHandle}&collection=${config.collections.base}.user`;
|
||||||
|
|
||||||
|
expect(userListUrl).toBe('https://syu.is/xrpc/com.atproto.repo.listRecords?repo=ai.syui.ai&collection=ai.syui.log.user');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('OAuth Login Flow', () => {
|
||||||
|
it('should use syu.is OAuth for handles in VITE_ATPROTO_HANDLE_LIST', () => {
|
||||||
|
mockEnv({
|
||||||
|
VITE_ATPROTO_HANDLE_LIST: '["syui.ai", "ai.syui.ai", "yui.syui.ai"]',
|
||||||
|
VITE_ATPROTO_PDS: 'syu.is'
|
||||||
|
});
|
||||||
|
|
||||||
|
const config = getAppConfig();
|
||||||
|
const handle = 'syui.ai';
|
||||||
|
|
||||||
|
// Check if handle is in allowed list
|
||||||
|
expect(config.allowedHandles).toContain(handle);
|
||||||
|
|
||||||
|
// Should use configured PDS for OAuth
|
||||||
|
const expectedAuthUrl = `https://${config.atprotoPds}/oauth/authorize`;
|
||||||
|
expect(expectedAuthUrl).toContain('syu.is');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use syu.is OAuth for *.syu.is handles', () => {
|
||||||
|
const handle = 'test.syu.is';
|
||||||
|
const pds = detectPdsFromHandle(handle);
|
||||||
|
expect(pds).toBe('syu.is');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Terminal display test output
|
||||||
|
export function runTerminalTests() {
|
||||||
|
console.log('\n=== OAuth App Tests ===\n');
|
||||||
|
|
||||||
|
// Test 1: Handle input behavior
|
||||||
|
console.log('1. Handle Input Detection:');
|
||||||
|
const handles = ['syui.ai', 'syui.syu.is', 'syui.syui.ai'];
|
||||||
|
handles.forEach(handle => {
|
||||||
|
const pds = detectPdsFromHandle(handle);
|
||||||
|
console.log(` ${handle} → PDS: ${pds}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test 2: Environment variable impact
|
||||||
|
console.log('\n2. Environment Variables:');
|
||||||
|
const config = getAppConfig();
|
||||||
|
console.log(` VITE_ATPROTO_PDS: ${config.atprotoPds}`);
|
||||||
|
console.log(` VITE_ADMIN_HANDLE: ${config.adminHandle}`);
|
||||||
|
console.log(` VITE_AI_HANDLE: ${config.aiHandle}`);
|
||||||
|
console.log(` VITE_OAUTH_COLLECTION: ${config.collections.base}`);
|
||||||
|
|
||||||
|
// Test 3: API endpoints
|
||||||
|
console.log('\n3. API Endpoints:');
|
||||||
|
const networkConfig = getNetworkConfig(config.atprotoPds);
|
||||||
|
console.log(` Admin PDS API: ${networkConfig.pdsApi}`);
|
||||||
|
console.log(` Admin Bsky API: ${networkConfig.bskyApi}`);
|
||||||
|
console.log(` User list URL: ${networkConfig.pdsApi}/xrpc/com.atproto.repo.listRecords?repo=${config.adminHandle}&collection=${config.collections.base}.user`);
|
||||||
|
|
||||||
|
// Test 4: OAuth routing
|
||||||
|
console.log('\n4. OAuth Routing:');
|
||||||
|
console.log(` Allowed handles: ${JSON.stringify(config.allowedHandles)}`);
|
||||||
|
console.log(` OAuth endpoint: https://${config.atprotoPds}/oauth/authorize`);
|
||||||
|
|
||||||
|
console.log('\n=== End Tests ===\n');
|
||||||
|
}
|
@@ -53,7 +53,6 @@ export class OAuthEndpointHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to generate JWKS:', error);
|
|
||||||
return new Response(JSON.stringify({ error: 'Failed to generate JWKS' }), {
|
return new Response(JSON.stringify({ error: 'Failed to generate JWKS' }), {
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
@@ -62,7 +61,6 @@ export class OAuthEndpointHandler {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If URL parsing fails, pass through to original fetch
|
// If URL parsing fails, pass through to original fetch
|
||||||
console.debug('URL parsing failed, passing through:', e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass through all other requests
|
// Pass through all other requests
|
||||||
@@ -136,6 +134,5 @@ export function registerOAuthServiceWorker() {
|
|||||||
const blob = new Blob([swCode], { type: 'application/javascript' });
|
const blob = new Blob([swCode], { type: 'application/javascript' });
|
||||||
const swUrl = URL.createObjectURL(blob);
|
const swUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
navigator.serviceWorker.register(swUrl).catch(console.error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -37,7 +37,6 @@ export class OAuthKeyManager {
|
|||||||
this.keyPair = await this.importKeyPair(keyData);
|
this.keyPair = await this.importKeyPair(keyData);
|
||||||
return this.keyPair;
|
return this.keyPair;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to load stored key, generating new one:', error);
|
|
||||||
localStorage.removeItem('oauth_private_key');
|
localStorage.removeItem('oauth_private_key');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +114,6 @@ export class OAuthKeyManager {
|
|||||||
const privateKey = await window.crypto.subtle.exportKey('jwk', keyPair.privateKey);
|
const privateKey = await window.crypto.subtle.exportKey('jwk', keyPair.privateKey);
|
||||||
localStorage.setItem('oauth_private_key', JSON.stringify(privateKey));
|
localStorage.setItem('oauth_private_key', JSON.stringify(privateKey));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to store private key:', error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user