Skip to content

Commit

Permalink
fix: issue with urls in published site
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Aug 1, 2020
1 parent 9dc3679 commit 0ac8e75
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions packages/dendron-cli/src/commands/build-site.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
DendronSiteConfig, DEngine,
DendronSiteConfig,
DEngine,
DNodeUtils,
Note
Note,
} from "@dendronhq/common-all";
import { resolvePath } from "@dendronhq/common-server";
import fs from "fs-extra";
Expand All @@ -26,7 +27,11 @@ type DendronJekyllProps = {
permalink?: string;
};

function wikiLinkToMd(note: Note, engine: DEngine) {
function wikiLinkToMd(
note: Note,
engine: DEngine,
opts?: { linkPrefix: string }
) {
let matches;
let doc = note.body;
do {
Expand All @@ -49,7 +54,11 @@ function wikiLinkToMd(note: Note, engine: DEngine) {
if (!noteFromLink) {
throw Error(`${mdLink} not found. file: ${note.fname}`);
}
const newLink = `[${title}](${noteFromLink.id})`;
let noteLink = noteFromLink.id;
if (opts?.linkPrefix) {
noteLink = `${opts.linkPrefix}/${noteLink}`;
}
const newLink = `[${title}](${noteLink})`;
doc = doc.replace(raw, newLink);
}
} while (matches);
Expand Down Expand Up @@ -78,20 +87,22 @@ function note2JekyllMdFile(
) {
const meta = DNodeUtils.getMeta(note, {
pullCustomUp: true,
ignoreNullParent: true
ignoreNullParent: true,
});
const jekyllProps: DendronJekyllProps = {
hpath: note.path
hpath: note.path,
};
let linkPrefix = "";
if (opts.noteRoot === meta.fname) {
jekyllProps["permalink"] = "/";
linkPrefix = path.basename(opts.notesDir);
}
// pull children of root to the top
if (note.parent?.fname === opts.noteRoot) {
delete meta["parent"];
}
// delete parent from root
note.body = wikiLinkToMd(note, opts.engine);
note.body = wikiLinkToMd(note, opts.engine, { linkPrefix });
const filePath = path.join(opts.notesDir, meta.id + ".md");
return fs.writeFile(
filePath,
Expand All @@ -106,15 +117,12 @@ export class BuildSiteCommand extends BaseCommand<CommandOpts, CommandOutput> {

const siteRoot = resolvePath(siteRootRaw, dendronRoot);
const siteNotesDir = "notes";
const siteNotesDirPath = path.join(
siteRoot,
siteNotesDir
);
const siteNotesDirPath = path.join(siteRoot, siteNotesDir);
const L = this.L.child({
ctx: "BuildSiteComman",
siteRoot,
dendronRoot,
noteRoot
noteRoot,
});
L.info({ msg: "enter", siteNotesDirPath });
fs.ensureDirSync(siteNotesDirPath);
Expand All @@ -138,10 +146,10 @@ export class BuildSiteCommand extends BaseCommand<CommandOpts, CommandOutput> {
note2JekyllMdFile(node, {
notesDir: siteNotesDirPath,
engine,
...config
...config,
})
);
node.children.forEach(n => nodes.push(n as Note));
node.children.forEach((n) => nodes.push(n as Note));
}

// TODO: need to rewrite links before this is ready
Expand All @@ -152,12 +160,11 @@ export class BuildSiteCommand extends BaseCommand<CommandOpts, CommandOutput> {
// docs/assets
const siteAssetsDir = path.join(siteRoot, assetsDir);


const copyP = new Promise((resolve, reject) => {
fs.copy(
path.join(vaultAssetsDir, "images"),
path.join(siteAssetsDir, "images"),
err => {
(err) => {
if (err) {
err.message += JSON.stringify({ vaultAssetsDir, siteAssetsDir });
reject(err);
Expand Down

0 comments on commit 0ac8e75

Please sign in to comment.