-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2154 Undecorate Obsidian node titles into core_title on publish #1318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
88e0037
c8385a3
7fe37bb
2ca1a8f
d55ba7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import type { DiscourseNodeInVault } from "./getDiscourseNodes"; | |
| import type { LocalConceptDataInput } from "@repo/database/inputTypes"; | ||
| import type { ObsidianDiscourseNodeData } from "./syncDgNodesToSupabase"; | ||
| import type { Json } from "@repo/database/dbTypes"; | ||
| import { extractContentFromTitle } from "./extractContentFromTitle"; | ||
|
|
||
| /** | ||
| * Get extra data (author, timestamps) from file metadata | ||
|
|
@@ -157,15 +158,24 @@ export const discourseRelationTripleSchemaToLocalConcept = ({ | |
| /** | ||
| * Convert discourse node instance (file) to LocalConceptDataInput | ||
| */ | ||
| export const discourseNodeInstanceToLocalConcept = ( | ||
| context: SupabaseContext, | ||
| nodeData: ObsidianDiscourseNodeData, | ||
| ): LocalConceptDataInput => { | ||
| export const discourseNodeInstanceToLocalConcept = ({ | ||
| context, | ||
| nodeData, | ||
| nodeTypesById, | ||
| }: { | ||
| context: SupabaseContext; | ||
| nodeData: ObsidianDiscourseNodeData; | ||
| nodeTypesById: Record<string, DiscourseNode>; | ||
| }): LocalConceptDataInput => { | ||
| const extraData = getNodeExtraData(nodeData.file, context.userId); | ||
| const { nodeInstanceId, nodeTypeId, importedFromRid, ...otherData } = | ||
| nodeData.frontmatter; | ||
| const literal_content: Record<string, Json> = { | ||
| label: nodeData.file.basename, | ||
| core_title: extractContentFromTitle( | ||
| nodeTypesById[nodeData.nodeTypeId]?.format ?? "", | ||
| nodeData.file.basename, | ||
|
sid597 marked this conversation as resolved.
|
||
| ), | ||
|
sid597 marked this conversation as resolved.
Comment on lines
+175
to
+178
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The write is unconditional on purpose: |
||
| source_data: otherData as unknown as Json, | ||
| }; | ||
| if (importedFromRid && typeof importedFromRid === "string") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,24 @@ | ||
| import { getDiscourseNodeFormatExpression } from "./getDiscourseNodeFormatExpression"; | ||
|
|
||
| export const extractContentFromTitle = (format: string, title: string): string => { | ||
| export const extractContentFromTitle = ( | ||
| format: string, | ||
| title: string, | ||
| ): string => { | ||
| if (!format) return title; | ||
|
|
||
| const placeholderRegex = /{([a-zA-Z]+)}/g; | ||
| const placeholders: string[] = []; | ||
| let placeholderMatch: RegExpExecArray | null; | ||
| while ((placeholderMatch = placeholderRegex.exec(format))) { | ||
| placeholders.push(placeholderMatch[1] ?? ""); | ||
| } | ||
| const regex = getDiscourseNodeFormatExpression(format); | ||
| const match = title.match(regex); | ||
| const match = regex.exec(title); | ||
| if (!match) return title; | ||
|
|
||
| return match?.[1]?.trim() || title; | ||
| const contentIndex = placeholders.findIndex( | ||
| (name) => name.toLowerCase() === "content", | ||
| ); | ||
| const capture = contentIndex >= 0 ? match[contentIndex + 1] : match[1]; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getDiscourseNodeFormatExpression turns every |
||
| return capture === undefined ? title : capture.trim(); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodeData.nodeTypeIdis the typed copy offrontmatter.nodeTypeId(same value;getDiscourseNodescopies it out). The destructurednodeTypeIdon line 171 exists to strip the key fromotherDatabefore it becomessource_data, and line 187 keeps using it with the pre-existingas string— switching that tonodeData.nodeTypeIdwould drop an assertion, left as is to avoid churn on a PR under review.