Skip to content

Commit

Permalink
fix(sync): next js export pod error (#3539)
Browse files Browse the repository at this point in the history
* fix(sync): next js export pod error

* spike: adding back dup note handling in publishing

* spike: fixing dendron note page compile warning
  • Loading branch information
jonathanyeung committed Sep 20, 2022
1 parent 3f09312 commit 7a2aafc
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 139 deletions.
3 changes: 3 additions & 0 deletions packages/engine-server/src/topics/site.ts
Expand Up @@ -36,6 +36,9 @@ import { HierarchyUtils, stripLocalOnlyTags } from "../utils";

const LOGGER_NAME = "SiteUtils";

/**
* @deprecated - prefer to use methods in unified/SiteUtils if they exist.
*/
export class SiteUtils {
static canPublish(opts: {
note: NoteProps;
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs-template/components/DendronNotePage.tsx
Expand Up @@ -119,7 +119,7 @@ export default function Note({
<Row gutter={20}>
<Col xs={24} md={18}>
{BannerAlert && <BannerAlert />}
<DendronNote noteContent={noteBody} config={config} />
<DendronNote noteContent={noteBody} />
{maybeCollection}
<DendronNoteGiscusWidget note={note} config={config} />
</Col>
Expand Down
1 change: 1 addition & 0 deletions packages/pods-core/src/builtin/NextjsExportPod.ts
Expand Up @@ -303,6 +303,7 @@ export class NextjsExportPod extends ExportPod<NextjsExportConfig> {
vault: note.vault,
config: engineConfig,
vaults: engine.vaults,
wsRoot: engine.wsRoot,
},
{ flavor: ProcFlavor.PUBLISHING }
);
Expand Down
213 changes: 96 additions & 117 deletions packages/unified/src/SiteUtils.ts
Expand Up @@ -5,15 +5,20 @@ import {
DendronPublishingConfig,
DendronSiteConfig,
DNodeUtils,
DuplicateNoteActionEnum,
DuplicateNoteBehavior,
DVault,
DVaultVisibility,
getSlugger,
HierarchyConfig,
IDendronError,
IntermediateDendronConfig,
isBlockAnchor,
NoteDicts,
NoteDictsUtils,
NoteProps,
NoteUtils,
UseVaultBehavior,
VaultUtils,
} from "@dendronhq/common-all";

Expand Down Expand Up @@ -489,121 +494,95 @@ export class SiteUtils {
}`;
}

// static handleDup(opts: {
// dupBehavior?: DuplicateNoteBehavior;
// allowStubs?: boolean;
// fname: string;
// config: IntermediateDendronConfig;
// noteCandidates: NoteProps[];
// noteDict: NotePropsByIdDict;
// vaults: DVault[];
// wsRoot: string;
// }) {
// const {
// vaults,
// wsRoot,
// fname,
// noteCandidates,
// noteDict,
// config,
// dupBehavior,
// allowStubs,
// } = _.defaults(opts, {
// dupBehavior: {
// action: DuplicateNoteActionEnum.useVault,
// payload: [],
// } as UseVaultBehavior,
// allowStubs: true,
// });
// // const ctx = "handleDup";
// let domainNote: NoteProps | undefined;
// TODO: Delete duplicate version in engine-server's SiteUtils.
static handleDup(opts: {
dupBehavior?: DuplicateNoteBehavior;
fname: string;
config: IntermediateDendronConfig;
noteCandidates: NoteProps[];
noteDict: NoteDicts;
vaults: DVault[];
wsRoot: string;
}) {
const {
vaults,
wsRoot,
fname,
noteCandidates,
noteDict,
config,
dupBehavior,
} = _.defaults(opts, {
dupBehavior: {
action: DuplicateNoteActionEnum.useVault,
payload: [],
} as UseVaultBehavior,
allowStubs: true,
});
// const ctx = "handleDup";
let domainNote: NoteProps | undefined;

if (_.isArray(dupBehavior.payload)) {
const vaultNames = dupBehavior.payload;
_.forEach(vaultNames, (vname) => {
if (domainNote) {
return;
}
const vault = VaultUtils.getVaultByNameOrThrow({
vname,
vaults,
});

// if (_.isArray(dupBehavior.payload)) {
// const vaultNames = dupBehavior.payload;
// _.forEach(vaultNames, (vname) => {
// if (domainNote) {
// return;
// }
// const vault = VaultUtils.getVaultByNameOrThrow({
// vname,
// vaults: engine.vaults,
// });
// const maybeNote = NoteUtils.getNoteByFnameFromEngine({
// fname,
// engine,
// vault,
// });
// if (maybeNote && maybeNote.stub && !allowStubs) {
// return;
// }
// if (
// maybeNote &&
// this.canPublish({
// config,
// note: maybeNote,
// wsRoot,
// vaults,
// })
// ) {
// domainNote = maybeNote;
// // const logger = createLogger(LOGGER_NAME);
// // logger.info({
// // ctx,
// // status: "found",
// // note: NoteUtils.toLogObj(domainNote),
// // });
// }
// });
// if (!domainNote) {
// throw new DendronError({
// message: `no notes found for ${fname} in vaults ${vaultNames}`,
// });
// }
// } else {
// const vault = dupBehavior.payload.vault;
// const maybeDomainNotes = noteCandidates.filter((n) =>
// VaultUtils.isEqual(n.vault, vault, engine.wsRoot)
// );
// // const logger = createLogger(LOGGER_NAME);
// if (maybeDomainNotes.length < 1) {
// // logger.error({
// // ctx: "filterByHierarchy",
// // msg: "dup-resolution: no note found",
// // vault,
// // });
// throw new DendronError({
// message: `no notes found for ${fname} in vault ${vault.fsPath}`,
// });
// }
// if (
// !this.canPublish({
// config,
// note: maybeDomainNotes[0],
// wsRoot,
// vaults,
// })
// ) {
// return;
// }
// domainNote = maybeDomainNotes[0];
// }
// const domainId = domainNote.id;
// // merge children
// domainNote.children = getUniqueChildrenIds(noteCandidates);
// // update parents
// domainNote.children.map((id) => {
// const maybeNote = noteDict[id];
// maybeNote.parent = domainId;
// });
// // const logger = createLogger(LOGGER_NAME);
// // logger.info({
// // ctx: "filterByHierarchy",
// // msg: "dup-resolution: resolving dup",
// // parent: domainNote.id,
// // children: domainNote.children,
// // });
// return domainNote;
// }
const maybeNote = NoteDictsUtils.findByFname(fname, noteDict, vault)[0];
if (
maybeNote &&
this.canPublish({
config,
note: maybeNote,
wsRoot,
vaults,
})
) {
domainNote = maybeNote;
}
});
if (!domainNote) {
throw new DendronError({
message: `no notes found for ${fname} in vaults ${vaultNames}`,
});
}
} else {
const vault = dupBehavior.payload.vault;
const maybeDomainNotes = noteCandidates.filter((n) =>
VaultUtils.isEqual(n.vault, vault, wsRoot)
);
if (maybeDomainNotes.length < 1) {
throw new DendronError({
message: `no notes found for ${fname} in vault ${vault.fsPath}`,
});
}
if (
!this.canPublish({
config,
note: maybeDomainNotes[0],
wsRoot,
vaults,
})
) {
return;
}
domainNote = maybeDomainNotes[0];
}
const domainId = domainNote.id;
// merge children
domainNote.children = getUniqueChildrenIds(noteCandidates);
// update parents
domainNote.children.map((id) => {
const maybeNote = noteDict.notesById[id];
maybeNote.parent = domainId;
});
return domainNote;
}

/**
* Is the current note equivalent ot the index of the published site?
Expand Down Expand Up @@ -636,6 +615,6 @@ export class SiteUtils {
}
}

// function getUniqueChildrenIds(notes: NoteProps[]): string[] {
// return _.uniq(notes.flatMap((ent) => ent.children));
// }
function getUniqueChildrenIds(notes: NoteProps[]): string[] {
return _.uniq(notes.flatMap((ent) => ent.children));
}
41 changes: 20 additions & 21 deletions packages/unified/src/remark/noteRefsV2.ts
Expand Up @@ -456,27 +456,26 @@ export function convertNoteRefASTV2(

// apply publish rules and do duplicate
if (shouldApplyPublishRules && !_.isUndefined(duplicateNoteConfig)) {
// JYTODO: Add back Handle Dup Logic
// const maybeNote = SiteUtils.handleDup({
// allowStubs: false,
// dupBehavior: duplicateNoteConfig,
// engine,
// config,
// fname: link.from.fname,
// noteCandidates: resp.data,
// noteDict: engine.notes,
// });
// if (!maybeNote) {
// return {
// error: undefined,
// data: [
// MdastUtils.genMDErrorMsg(
// `Error rendering note reference for ${link.from.fname}`
// ),
// ],
// };
// }
// note = maybeNote;
const maybeNote = SiteUtils.handleDup({
dupBehavior: duplicateNoteConfig,
config,
vaults,
wsRoot,
fname: link.from.fname,
noteCandidates: data,
noteDict: noteCacheForRenderDict!,
});
if (!maybeNote) {
return {
error: undefined,
data: [
MdastUtils.genMDErrorMsg(
`Error rendering note reference for ${link.from.fname}`
),
],
};
}
note = maybeNote;
} else {
// no need to apply publish rules, try to pick the one that is in same vault

Expand Down

0 comments on commit 7a2aafc

Please sign in to comment.