Skip to content

Commit 1011d41

Browse files
committed
add authorName to frontmatter
1 parent 41502c1 commit 1011d41

4 files changed

Lines changed: 26 additions & 22 deletions

File tree

apps/obsidian/src/components/ImportNodesModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
120120
createdAt: node.createdAt,
121121
modifiedAt: node.modifiedAt,
122122
filePath: node.filePath,
123+
authorName: node.authorName,
123124
});
124125
}
125126

apps/obsidian/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ export default class DiscourseGraphPlugin extends Plugin {
330330
if (!this.settings.showIdsInFrontmatter) {
331331
keysToHide.push(
332332
...[
333-
"nodeTypeId",
333+
"authorName",
334+
"importedAssets",
334335
"importedFromRid",
336+
"lastModified",
335337
"nodeInstanceId",
338+
"nodeTypeId",
336339
"publishedToGroups",
337-
"lastModified",
338-
"importedAssets",
339340
],
340341
);
341342
keysToHide.push(...this.settings.relationTypes.map((rt) => rt.id));

apps/obsidian/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export type ImportableNode = {
9797
createdAt?: number;
9898
modifiedAt?: number;
9999
filePath?: string;
100+
authorName?: string;
100101
};
101102

102103
export type GroupWithNodes = {

apps/obsidian/src/utils/importNodes.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export const getAvailableGroupIds = async (
3636
return (data || []).map((g) => g.group_id);
3737
};
3838

39+
type publishedNode = {
40+
source_local_id: string;
41+
space_id: number;
42+
text: string;
43+
createdAt: number;
44+
modifiedAt: number;
45+
filePath: string | undefined;
46+
authorName: string | undefined;
47+
};
48+
3949
export const getPublishedNodesForGroups = async ({
4050
client,
4151
groupIds,
@@ -44,16 +54,7 @@ export const getPublishedNodesForGroups = async ({
4454
client: DGSupabaseClient;
4555
groupIds: string[];
4656
currentSpaceId: number;
47-
}): Promise<
48-
Array<{
49-
source_local_id: string;
50-
space_id: number;
51-
text: string;
52-
createdAt: number;
53-
modifiedAt: number;
54-
filePath: string | undefined;
55-
}>
56-
> => {
57+
}): Promise<Array<publishedNode>> => {
5758
if (groupIds.length === 0) {
5859
return [];
5960
}
@@ -63,7 +64,7 @@ export const getPublishedNodesForGroups = async ({
6364
const { data, error } = await client
6465
.from("my_contents")
6566
.select(
66-
"source_local_id, space_id, text, created, last_modified, variant, metadata",
67+
"source_local_id, space_id, text, created, last_modified, variant, metadata, author:my_accounts!author_id(name)",
6768
)
6869
.neq("space_id", currentSpaceId);
6970

@@ -83,6 +84,7 @@ export const getPublishedNodesForGroups = async ({
8384
created: string | null;
8485
last_modified: string | null;
8586
variant: string | null;
87+
author: { name: string } | null;
8688
metadata: Json;
8789
};
8890

@@ -95,14 +97,7 @@ export const getPublishedNodesForGroups = async ({
9597
groups.get(k)!.push(row);
9698
}
9799

98-
const nodes: Array<{
99-
source_local_id: string;
100-
space_id: number;
101-
text: string;
102-
createdAt: number;
103-
modifiedAt: number;
104-
filePath: string | undefined;
105-
}> = [];
100+
const nodes: Array<publishedNode> = [];
106101

107102
for (const rows of groups.values()) {
108103
const withDate = rows.filter(
@@ -133,6 +128,7 @@ export const getPublishedNodesForGroups = async ({
133128
createdAt,
134129
modifiedAt,
135130
filePath,
131+
authorName: latest.author ? latest.author.name : undefined,
136132
});
137133
}
138134

@@ -975,6 +971,7 @@ type ParsedFrontmatter = {
975971
nodeTypeId?: string;
976972
nodeInstanceId?: string;
977973
publishedToGroups?: string[];
974+
authorName?: string;
978975
[key: string]: unknown;
979976
};
980977

@@ -1105,6 +1102,7 @@ const processFileContent = async ({
11051102
filePath,
11061103
importedCreatedAt,
11071104
importedModifiedAt,
1105+
authorName,
11081106
}: {
11091107
plugin: DiscourseGraphPlugin;
11101108
client: DGSupabaseClient;
@@ -1115,6 +1113,7 @@ const processFileContent = async ({
11151113
filePath: string;
11161114
importedCreatedAt?: number;
11171115
importedModifiedAt?: number;
1116+
authorName?: string;
11181117
}): Promise<
11191118
{ file: TFile; error?: never } | { file?: never; error: string }
11201119
> => {
@@ -1173,6 +1172,7 @@ const processFileContent = async ({
11731172
"note",
11741173
);
11751174
record.lastModified = importedModifiedAt;
1175+
if (authorName) record.authorName = authorName;
11761176
},
11771177
stat,
11781178
);
@@ -1322,6 +1322,7 @@ export const importSelectedNodes = async ({
13221322
filePath: finalFilePath,
13231323
importedCreatedAt: createdAt,
13241324
importedModifiedAt: modifiedAt,
1325+
authorName: node.authorName,
13251326
});
13261327

13271328
if (result.error) {

0 commit comments

Comments
 (0)