Search full-text (blogData.text), related posts snippet, minify tool, generator event guard; README base+related
This commit is contained in:
+47
-1
@@ -47,6 +47,38 @@ if (api.originEntity && isGeneratedNoteId(api.originEntity.noteId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ---- P2: only rebuild on events that can affect the generated pages ----
|
||||
// (avoids full rebuild on every snippet/CSS edit, image upload, self-set shareAlias, ...)
|
||||
const GEN_RELEVANT_LABELS = new Set([
|
||||
"publish", "date", "category", "tags", "summary", "state",
|
||||
"blogGarden", "blogCategory", "blogNoArticles", "iconClass"
|
||||
]);
|
||||
const GEN_SKIP_RELATIONS = new Set([
|
||||
"shareHtml", "shareCss", "shareTemplate", "shareFavicon", "shareOpenGraphImage",
|
||||
"runOnNoteContentChange", "runOnAttributeChange", "runOnAttributeCreation",
|
||||
"runOnNoteTitleChange", "runOnNoteCreation", "runOnChildNoteCreation",
|
||||
"runOnBranchDeletion", "runOnEntityChange"
|
||||
]);
|
||||
function shouldRebuild() {
|
||||
const o = api.originEntity;
|
||||
const ev = api.originEvent || "";
|
||||
if (!o) return true;
|
||||
if (/contentChange/i.test(ev)) {
|
||||
// Article body edits don't change the index/feed/tag pages (only summary labels do).
|
||||
// Keep the refresh only for thumbnail image replacements (index shows the thumb).
|
||||
const title = o.title || "";
|
||||
if (!/^(?:thumb|.+_thumb)\.[A-Za-z0-9]+$/i.test(title)) return false;
|
||||
}
|
||||
if (o.type === "label" && !GEN_RELEVANT_LABELS.has(o.name)) return false;
|
||||
if (o.type === "relation" && GEN_SKIP_RELATIONS.has(o.name)) return false;
|
||||
if (o.type === "branch") return false; // publish/unpublish covers clone+move via label events
|
||||
return true;
|
||||
}
|
||||
if (!shouldRebuild()) {
|
||||
api.log("blog_generator: event skipped (no index impact)");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
run();
|
||||
} catch (e) {
|
||||
@@ -392,6 +424,19 @@ function run() {
|
||||
})(blogRoot, 0);
|
||||
}
|
||||
|
||||
function plainText(a) {
|
||||
try {
|
||||
return String(a.getContent() || "")
|
||||
.replace(/<script[\s\S]*?<\/script>/gi, " ")
|
||||
.replace(/<style[\s\S]*?<\/style>/gi, " ")
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.replace(/&[a-z#0-9]+;/gi, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.slice(0, 1500);
|
||||
} catch (e) { return ""; }
|
||||
}
|
||||
|
||||
function buildBlogData() {
|
||||
const systemNote = api.getNote(BLOG_SYSTEM_NOTE_ID);
|
||||
if (!systemNote) return;
|
||||
@@ -405,7 +450,8 @@ function run() {
|
||||
tags: tagList(a),
|
||||
category: a.getLabelValue("category") || "",
|
||||
date: (a.getLabelValue("date") || a.dateCreated).slice(0, 10),
|
||||
dateText: dateText(a.getLabelValue("date") || a.dateCreated)
|
||||
dateText: dateText(a.getLabelValue("date") || a.dateCreated),
|
||||
text: plainText(a)
|
||||
}));
|
||||
const html = `<script>window.blogData = ${JSON.stringify({ articles: list })};</script>`;
|
||||
if (dataNote.getContent() !== html) {
|
||||
|
||||
Reference in New Issue
Block a user