Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/utils/matchDiscourseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ const matchDiscourseNode = ({
}
| { uid: string }
)) => {
// Handle specification with single "has title" clause
if (
specification.length === 1 &&
specification[0].type === "clause" &&
specification[0].relation === "has title"
) {
const title =
"title" in rest ? rest.title : getPageTitleByPageUid(rest.uid);
const regex = new RegExp(specification[0].target.slice(1, -1));
return !specification[0].not && regex.test(title);
}

// Handle any other specification
if (specification.length) {
const where = replaceDatalogVariables(
[{ from: text, to: "node" }],
specification.flatMap((c) =>
conditionToDatalog(c)
)
specification.flatMap((c) => conditionToDatalog(c))
).map((c) => compileDatalog(c, 0));
const firstClause =
"title" in rest
Expand All @@ -35,6 +46,8 @@ const matchDiscourseNode = ({
`[:find ?node :where ${firstClause} ${where.join(" ")}]`
).length;
}

// Fallback to format expression
const title = "title" in rest ? rest.title : getPageTitleByPageUid(rest.uid);
return getDiscourseNodeFormatExpression(format).test(title);
};
Expand Down
Loading