working on obsidian plugin
This commit is contained in:
@@ -161,31 +161,37 @@ export function createServer(customSiteDir, customPostsDir, customAssetsDir) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.mkdirSync(postsDir, { recursive: true });
|
try {
|
||||||
fs.mkdirSync(assetsDir, { recursive: true });
|
fs.mkdirSync(postsDir, { recursive: true });
|
||||||
|
fs.mkdirSync(assetsDir, { recursive: true });
|
||||||
|
|
||||||
const normalizedContent = normalizeObsidianMarkdown(content);
|
const normalizedContent = normalizeObsidianMarkdown(content);
|
||||||
const targetFilePath = path.join(postsDir, `${cleanSlug}.md`);
|
const targetFilePath = path.join(postsDir, `${cleanSlug}.md`);
|
||||||
fs.writeFileSync(targetFilePath, normalizedContent, "utf-8");
|
fs.writeFileSync(targetFilePath, normalizedContent, "utf-8");
|
||||||
|
|
||||||
if (Array.isArray(assets)) {
|
if (Array.isArray(assets)) {
|
||||||
for (const asset of assets) {
|
for (const asset of assets) {
|
||||||
if (asset && asset.filename && asset.data) {
|
if (asset && asset.filename && asset.data) {
|
||||||
const cleanName = path.basename(asset.filename).replace(/[^a-zA-Z0-9._-]/g, "");
|
const cleanName = path.basename(asset.filename).replace(/[^a-zA-Z0-9._-]/g, "");
|
||||||
if (cleanName) {
|
if (cleanName) {
|
||||||
const assetPath = path.join(assetsDir, cleanName);
|
const assetPath = path.join(assetsDir, cleanName);
|
||||||
fs.writeFileSync(assetPath, Buffer.from(asset.data, "base64"));
|
fs.writeFileSync(assetPath, Buffer.from(asset.data, "base64"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
res.writeHead(200, { "Content-Type": "application/json" });
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
status: "published",
|
status: "published",
|
||||||
slug: cleanSlug,
|
slug: cleanSlug,
|
||||||
path: `/posts/${cleanSlug}/`
|
path: `/posts/${cleanSlug}/`
|
||||||
}));
|
}));
|
||||||
|
} catch (writeErr) {
|
||||||
|
console.error("[Ingestion API] Error saving post/assets:", writeErr);
|
||||||
|
res.writeHead(500, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: `Failed to write file to disk: ${writeErr.message}` }));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user