feat: unify notes into posts stream with folder tree and CI
notebook-ci / build-push-deploy (push) Successful in 41s
notebook-ci / build-push-deploy (push) Successful in 41s
Merge notes/posts into a single posts collection, redirect /notes to /posts, add folder browsing, and wire Gitea Actions deploy workflow.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 共享:从本地 Vault 目录同步公开笔记到 src/content/notes
|
||||
* 共享:从本地 Vault 同步到 src/content/posts(统一文章流)
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
@@ -84,23 +84,33 @@ export function ensureTitle(raw, filename) {
|
||||
/**
|
||||
* @param {object} opts
|
||||
* @param {string} opts.vault 源目录
|
||||
* @param {string} opts.notesOut 目标 notes 目录
|
||||
* @param {string} [opts.postsOut] 目标 posts 目录(文章流)
|
||||
* @param {string} [opts.notesOut] 兼容旧参数,等同 postsOut
|
||||
* @param {string} opts.assetsOut 目标资源目录
|
||||
* @param {boolean} [opts.dryRun]
|
||||
* @param {boolean} [opts.clean] 同步前清空 notesOut 下旧文件(不含子目录 .gitkeep 类)
|
||||
* @param {boolean} [opts.clean] 同步前清空目标目录
|
||||
*/
|
||||
export function syncLocalVault({ vault, notesOut, assetsOut, dryRun = false, clean = false }) {
|
||||
export function syncLocalVault({
|
||||
vault,
|
||||
postsOut,
|
||||
notesOut,
|
||||
assetsOut,
|
||||
dryRun = false,
|
||||
clean = false,
|
||||
}) {
|
||||
const outDir = postsOut || notesOut;
|
||||
if (!outDir) throw new Error('需要 postsOut(或兼容 notesOut)');
|
||||
if (!fs.existsSync(vault)) {
|
||||
throw new Error(`Vault 路径不存在: ${vault}`);
|
||||
}
|
||||
|
||||
ensureDir(notesOut);
|
||||
ensureDir(outDir);
|
||||
ensureDir(assetsOut);
|
||||
|
||||
if (clean && !dryRun) {
|
||||
for (const name of fs.readdirSync(notesOut)) {
|
||||
for (const name of fs.readdirSync(outDir)) {
|
||||
if (name === '.gitkeep') continue;
|
||||
fs.rmSync(path.join(notesOut, name), { recursive: true, force: true });
|
||||
fs.rmSync(path.join(outDir, name), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +140,7 @@ export function syncLocalVault({ vault, notesOut, assetsOut, dryRun = false, cle
|
||||
}
|
||||
|
||||
const destRel = relPosix.replace(/\.mdx?$/i, '') + path.extname(full);
|
||||
const dest = path.join(notesOut, destRel);
|
||||
const dest = path.join(outDir, destRel);
|
||||
const content = ensureTitle(raw, full);
|
||||
|
||||
if (dryRun) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
* 其它:
|
||||
* --dry-run 只列文件
|
||||
* --clean 同步前清空 src/content/notes
|
||||
* --clean 同步前清空 src/content/posts
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
@@ -37,7 +37,7 @@ const dryRun = process.argv.includes('--dry-run');
|
||||
const clean = process.argv.includes('--clean');
|
||||
const forceWebdav = process.argv.includes('--webdav');
|
||||
|
||||
const notesOut = path.join(root, 'src/content/notes');
|
||||
const postsOut = path.join(root, 'src/content/posts');
|
||||
const assetsOut = path.join(root, 'public/assets');
|
||||
const cacheDir = path.join(root, '.cache/nutstore-vault');
|
||||
|
||||
@@ -212,8 +212,8 @@ async function main() {
|
||||
if (local && fs.existsSync(local) && !forceWebdav) {
|
||||
console.log('模式: 坚果云本地同步盘');
|
||||
console.log(`Vault: ${local}`);
|
||||
console.log(`Out: ${notesOut}`);
|
||||
const r = syncLocalVault({ vault: local, notesOut, assetsOut, dryRun, clean });
|
||||
console.log(`Out: ${postsOut}(统一文章流)`);
|
||||
const r = syncLocalVault({ vault: local, postsOut, assetsOut, dryRun, clean });
|
||||
console.log(
|
||||
dryRun
|
||||
? `[dry-run] 将同步 ${r.mdCount} 篇笔记, ${r.assetCount} 个资源, 跳过 ${r.skipCount}`
|
||||
@@ -248,7 +248,7 @@ async function main() {
|
||||
console.log('模式: 坚果云 WebDAV');
|
||||
console.log(`Remote: ${rootUrl}`);
|
||||
console.log(`Cache: ${cacheDir}`);
|
||||
console.log(`Out: ${notesOut}`);
|
||||
console.log(`Out: ${postsOut}(统一文章流)`);
|
||||
|
||||
console.log('列出远程文件…');
|
||||
const files = await listRemoteFiles(rootUrl.endsWith('/') ? rootUrl : rootUrl + '/');
|
||||
@@ -261,7 +261,7 @@ async function main() {
|
||||
|
||||
const r = syncLocalVault({
|
||||
vault: cacheDir,
|
||||
notesOut,
|
||||
postsOut,
|
||||
assetsOut,
|
||||
dryRun: false,
|
||||
clean,
|
||||
|
||||
@@ -27,15 +27,15 @@ const vault =
|
||||
process.env.NUTSTORE_LOCAL_PATH ||
|
||||
DEFAULT_VAULT;
|
||||
|
||||
const notesOut = path.join(root, 'src/content/notes');
|
||||
const postsOut = path.join(root, 'src/content/posts');
|
||||
const assetsOut = path.join(root, 'public/assets');
|
||||
|
||||
try {
|
||||
console.log(`Vault: ${vault}`);
|
||||
console.log(`Out: ${notesOut}`);
|
||||
console.log(`Out: ${postsOut}(统一文章流)`);
|
||||
const { mdCount, assetCount, skipCount } = syncLocalVault({
|
||||
vault,
|
||||
notesOut,
|
||||
postsOut,
|
||||
assetsOut,
|
||||
dryRun,
|
||||
clean,
|
||||
|
||||
Reference in New Issue
Block a user