Skip to content

Commit

Permalink
fix(pods): bad title for naked wiki links
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Aug 15, 2020
1 parent 3f93b31 commit 64c04ff
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
5 changes: 5 additions & 0 deletions fixtures/store/refactor.one.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
---
id: refactor.one
title: refactor-one
---

- [[refactor.two]]
6 changes: 6 additions & 0 deletions packages/common-server/src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class EngineTestUtils {
);
}

/**
* setupStoreDir
* @param fixturesDir
* @param dirPath
* @param opts : copyFixtures, true by default
*/
static setupStoreDir(
fixturesDir: string,
dirPath: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`build-site basic: bond-foo 1`] = `
"
- [refactor-one](refactor.one)
"
`;
58 changes: 53 additions & 5 deletions packages/dendron-cli/src/commands/__tests__/build-site.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
import { Note } from "@dendronhq/common-all/src";
import { DEngine } from "@dendronhq/common-all";
import fs from "fs-extra";
import {
LernaTestUtils,
EngineTestUtils,
FileTestUtils,
readMD,
} from "@dendronhq/common-server";
import { DendronEngine } from "@dendronhq/engine-server";
import { BuildSiteCommand } from "../build-site";
import path from "path";

test("imageLinkConverter", () => {
const note = Note.createRoot();
note.body = "![ ](assets/image)";
expect(1).toEqual(1);
function setupTmpDendronDir() {
return EngineTestUtils.setupStoreDir(
LernaTestUtils.getFixturesDir("store"),
FileTestUtils.tmpDir().name
);
}

describe("build-site", () => {
let root: string;
let engine: DEngine;

beforeEach(() => {
root = setupTmpDendronDir();
engine = DendronEngine.getOrCreateEngine({
root,
forceNew: true,
mode: "exact",
});
});

afterEach(() => {
// expect(actualFiles).toEqual(expectedFiles);
console.log("bond");
console.log(root);
// fs.removeSync(root);
});
test("basic", async () => {
const siteRoot = FileTestUtils.tmpDir();
await engine.init();
const config = {
noteRoot: "root",
siteRoot: siteRoot.name,
};
const dendronRoot = root;
await new BuildSiteCommand().execute({ engine, config, dendronRoot });
const buildDir = path.join(siteRoot.name, "notes");
const { data, content } = readMD(path.join(buildDir, "foo.md"));
expect(content).toMatchSnapshot("bond-foo");
expect(data.id).toEqual("foo");
expect(content.indexOf("- [refactor-one](refactor.one)") >= 0).toBe(true);
expect(1).toEqual(1);
});
});
3 changes: 0 additions & 3 deletions packages/dendron-cli/src/commands/__tests__/sanity.spec.ts

This file was deleted.

6 changes: 4 additions & 2 deletions packages/dendron-cli/src/commands/build-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ function wikiLinkToMd(
// @ts-ignore
const { raw, link } = matches.groups;
const [first, rest] = link.split("|");
let title: string;
let title: string | undefined;
let mdLink: string;
// we have a piped title
if (rest) {
title = _.trim(first);
mdLink = _.trim(rest);
} else {
title = _.trim(note.title);
mdLink = _.trim(first);
}
const noteFromLink = _.find(engine.notes, { fname: mdLink });
if (!noteFromLink) {
throw Error(`${mdLink} not found. file: ${note.fname}`);
}
if (!title) {
title = _.trim(noteFromLink.title);
}
let noteLink = noteFromLink.id;
if (opts?.linkPrefix) {
noteLink = `${opts.linkPrefix}/${noteLink}`;
Expand Down

0 comments on commit 64c04ff

Please sign in to comment.