Update docs and sort content

This commit is contained in:
github-actions[bot]
2024-11-29 11:14:45 +00:00
parent 3881cd6173
commit 09cd161c84
2 changed files with 349 additions and 0 deletions

View File

@ -0,0 +1,296 @@
---
slug: synchronize-profiles-to-remote-and-local-on-a-regular-basis
title: 使用github action定时同步obsidian内容到博客仓库
date: 2024-11-29
author: KazooTTT
type: Post
status: Published
tags:
finished: true
published: true
category:
description:
---
## github action
目标仓库以及具体目录可以根据自己的项目来定
``` yaml
name: Update Docs
on:
push:
paths:
- "content/**"
- "scripts/build_docs.cjs"
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v2
with:
token: ${{ secrets.PAT_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "20"
- name: Install dependencies
run: |
echo "Installing dependencies in source repository..."
npm install
echo "Dependencies installed successfully"
- name: Build docs
run: |
echo "Starting docs build..."
npm run build:docs:server
echo "Docs built successfully"
- name: Checkout target repository
uses: actions/checkout@v2
with:
repository: kazoottt/kazoottt-blog
path: kazoottt-blog
token: ${{ secrets.PAT_TOKEN }}
- name: Copy built docs to target repository
run: |
echo "Starting copy process..."
echo "Content of astroContent before copy:"
cp -rv astroContent/* kazoottt-blog/src/content/post/
echo "Content of astroContent copy done"
- name: Setup target repository
run: |
cd kazoottt-blog
echo "Configuring git..."
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
echo "Installing dependencies in target repository..."
npm install
echo "Running sort..."
npm run sort
- name: Check for changes and commit
run: |
cd kazoottt-blog
if [[ -n $(git status -s) ]]; then
git add .
git commit -m "Update docs and sort content"
git push
else
echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
```
PAT_TOKEN申请
[Sign in to GitHub · GitHub](https://github.com/settings/tokens)
需要权限repo, workflow
![image.png](https://pictures.kazoottt.top/2024/11/20241129-d27ae43fa5ad1344d66dff2e9d79c70e.png)
## obsidian模板
published是true且notAstro不为true的时候会被发布到另外一个仓库
```
---
title: {{title}}
date: {{date}}
author: KazooTTT
type: Post
status: Published
tags: []
finished: false
published: false
category:
slug:
description:
notAstro:
---
```
## 脚本 scripts/build_docs.cjs
依赖安装
```
npm install gray-matter
```
可以配置一些不想同步的文件夹
``` js
const fs = require("fs").promises
const fsSync = require("fs")
const path = require("path")
const matter = require("gray-matter")
const { execSync } = require("child_process")
const CONFIG = {
outputDir: "astroContent",
inputDir: "./content",
ignoreList: [
".github",
".obsidian",
"草稿箱",
"模板",
"attachment",
"记录",
"导航用",
"微信读书",
],
validExtensions: [".md"],
// Local specific config
localDestinationRoot: "", // to edit
localDestination: "", // to edit
}
/**
* Ensures output directory exists
*/
function initializeOutputDir() {
if (!fsSync.existsSync(CONFIG.outputDir)) {
fsSync.mkdirSync(CONFIG.outputDir, { recursive: true })
}
}
/**
* Validates if a file should be processed based on its metadata
*/
function shouldProcessFile(frontMatter) {
return frontMatter.published === true && !frontMatter.notAstro
}
/**
* Processes a single markdown file
*/
async function processMarkdownFile(fullPath, outputPath) {
try {
const fileContent = await fs.readFile(fullPath, "utf8")
const { data } = matter(fileContent)
if (shouldProcessFile(data)) {
await fs.copyFile(fullPath, outputPath)
console.log(`✓ Copied: ${path.relative(CONFIG.inputDir, fullPath)}`)
}
} catch (error) {
console.error(`Error processing file ${fullPath}:`, error.message)
}
}
/**
* Recursively processes directories and files
*/
async function processDirectory(dir) {
try {
const files = await fs.readdir(dir)
await Promise.all(
files.map(async (file) => {
const fullPath = path.join(dir, file)
const relativePath = path.relative(CONFIG.inputDir, fullPath)
const outputPath = path.join(CONFIG.outputDir, relativePath)
const stats = await fs.stat(fullPath)
if (stats.isDirectory()) {
if (CONFIG.ignoreList.includes(file)) return
await fs.mkdir(outputPath, { recursive: true })
await processDirectory(fullPath)
} else if (path.extname(file) === ".md" && file !== "index.md") {
await processMarkdownFile(fullPath, outputPath)
}
}),
)
} catch (error) {
console.error(`Error processing directory ${dir}:`, error.message)
}
}
/**
* Copies processed files to final destination and commits changes
*/
async function copyToLocalDestination() {
try {
// Remove existing content
if (fsSync.existsSync(CONFIG.localDestination)) {
await fs.rm(CONFIG.localDestination, { recursive: true })
}
// Create destination directory
await fs.mkdir(CONFIG.localDestination, { recursive: true })
// Copy files
const files = await fs.readdir(CONFIG.outputDir)
await Promise.all(
files.map(async (file) => {
const sourcePath = path.join(CONFIG.outputDir, file)
const destPath = path.join(CONFIG.localDestination, file)
await fs.rename(sourcePath, destPath)
}),
)
console.log("Content has been successfully copied to the local destination.")
// Commit changes
execSync(`cd ${path.dirname(CONFIG.localDestination)} && npm run sort`)
execSync(`git add ${CONFIG.localDestination} && git commit -m "update content"`)
// push changes
// execSync(`git push`)
} catch (error) {
console.error("Error copying to destination:", error.message)
}
}
/**
* Cleans up the temporary output directory
*/
async function cleanupOutputDir() {
try {
if (fsSync.existsSync(CONFIG.outputDir)) {
await fs.rm(CONFIG.outputDir, { recursive: true })
}
console.log("Cleaned up temporary directory.")
} catch (error) {
console.error("Error cleaning up:", error.message)
}
}
/**
* Main execution
*/
async function main() {
try {
const isLocalBuild = process.argv.includes("--local")
console.log(`Starting document processing... (${isLocalBuild ? "local" : "server"} build)`)
initializeOutputDir()
await processDirectory(CONFIG.inputDir)
if (isLocalBuild) {
await copyToLocalDestination()
await cleanupOutputDir()
}
console.log("Document processing completed successfully!")
} catch (error) {
console.error("Fatal error:", error.message)
}
}
main()
```

View File

@ -0,0 +1,53 @@
---
title: 2024-11-29 星期五
date: 2024-11-29
day_of_week: 星期五
author: KazooTTT
tags:
- 日记
description:
slug: diary-2024-11-29
published: true
category: 日记-2024-11
---
qube如何集成到github:
[GitHub Integration | Mapping your organization into SonarQube - YouTube](https://www.youtube.com/watch?v=6zvBuZr8CeI)
Image HTTP code 409 is in use. Delete the container that's using it and try again.
先删除container再删除volume
沉浸式翻译使用ollama
如何区分重启和刷新按钮
windows有没有像macos一样的窗口管理工具loop raycast之类的
[Adobe Express](https://new.express.adobe.com/tools/convert-to-svg)
covnert image to svg (需要登录)
![image.png](https://pictures.kazoottt.top/2024/11/20241129-771df278cae6c89066af0a9a882f3ff9.png)
[Canvas vs. SVG - 最佳实践 - 使用手册 - Apache ECharts](https://echarts.apache.org/handbook/zh/best-practices/canvas-vs-svg/)
> [!note]
> 选择哪种渲染器,我们可以根据软硬件环境、数据量、功能需求综合考虑。
> - 在软硬件环境较好,数据量不大的场景下,两种渲染器都可以适用,并不需要太多纠结。
> - 在环境较差,出现性能问题需要优化的场景下,可以通过试验来确定使用哪种渲染器。比如有这些经验:
> - 在需要创建很多 ECharts 实例且浏览器易崩溃的情况下(可能是因为 Canvas 数量多导致内存占用超出手机承受能力),可以使用 SVG 渲染器来进行改善。大略的说,如果图表运行在低端安卓机,或者我们在使用一些特定图表如 [水球图](https://ecomfe.github.io/echarts-liquidfill/example/) SVG 渲染器可能效果更好。
> - 数据量较大(经验判断 > 1k、较多交互时建议选择 Canvas 渲染器。
我什么时候可以做到用canvas手搓这种图
![image.png](https://pictures.kazoottt.top/2024/11/20241129-60d83ca2693fd5e9774743f352039c2b.png)
最近可以做的事情:
编辑器图片上传重构
编辑器高度修改
行间高度调整
用rn重写移动端
ml资源整合
vtk、图形学学习
obsidian插件 ollama generate slug tags