Skip to content
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

feat(publish): add private note config #3226

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 43 additions & 151 deletions packages/common-all/data/dendron-yml.validator.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/common-all/src/constants/configs/publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,9 @@ export const PUBLISHING: DendronConfigEntryCollection<DendronPublishingConfig> =
label: "Add a custom banner to the site",
desc: "EXPERIMENTAL: do not use",
},
privateNoteBehavior: {
label:
"Set how wikilinks and note references are converted when publishing",
desc: "When the note that a wikilink points to is private and when privateNoteBehavior is set to `aliasFallback`, it's replaced with a paragraph that contains an the link's alias",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type DendronPublishingConfig = {
cognitoClientId?: string;
enablePrettyLinks: boolean;
siteBanner?: string;
privateNoteBehavior: "privateLink" | "aliasFallback";
};

export type CleanDendronPublishingConfig = DendronPublishingConfig &
Expand Down Expand Up @@ -108,5 +109,6 @@ export function genDefaultPublishingConfig(): DendronPublishingConfig {
enableRandomlyColoredTags: true,
enableTaskNotes: true,
enablePrettyLinks: true,
privateNoteBehavior: "privateLink",
};
}
48 changes: 33 additions & 15 deletions packages/engine-server/src/markdown/remark/dendronPub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ConfigUtils,
DendronError,
DendronPublishingConfig,
DEngineClient,
DVault,
ERROR_SEVERITY,
Expand Down Expand Up @@ -394,23 +395,40 @@ function plugin(this: Unified.Processor, opts?: PluginOpts): Transformer {
],
} as RehypeLinkData;

const privateBehavior = (
ConfigUtils.getPublishingConfig(config) as DendronPublishingConfig
).privateNoteBehavior;

if (value === "403") {
_node.data = {
alias,
hName: "a",
hProperties: {
title: "Private",
href: "https://wiki.dendron.so/notes/hfyvYGJZQiUwQaaxQO27q.html",
target: "_blank",
class: "private",
},
hChildren: [
{
type: "text",
value: `${alias} (Private)`,
if (privateBehavior === "aliasFallback" && data.alias) {
_node.data = {
alias,
type: "paragraph",
children: [
{
type: "text",
value: alias,
},
],
};
} else {
_node.data = {
alias,
hName: "a",
hProperties: {
title: "Private",
href: "https://wiki.dendron.so/notes/hfyvYGJZQiUwQaaxQO27q.html",
target: "_blank",
class: "private",
},
],
} as RehypeLinkData;
hChildren: [
{
type: "text",
value: `${alias} (Private)`,
},
],
} as RehypeLinkData;
}
}
}
if (node.type === DendronASTTypes.REF_LINK_V2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DEngineClient,
DVault,
IntermediateDendronConfig,
StrictConfigV5,
VaultUtils,
WorkspaceOpts,
} from "@dendronhq/common-all";
Expand Down Expand Up @@ -59,6 +60,13 @@ const verifyPrivateLink = async (
});
};

const verifyAlias = async (vfile: VFile, value: string, capitalize = true) => {
return TestUnifiedUtils.verifyAlias({
contents: vfile.contents as string,
value: capitalize ? _.capitalize(value) : value,
});
};

function verifyPublicLink(resp: any, match: string) {
return checkString(resp.contents as string, `<a href="/notes/${match}">`);
}
Expand Down Expand Up @@ -202,20 +210,93 @@ describe("GIVEN dendronPub", () => {
});

describe("WHEN publish and private hierarchies", () => {
const fname = fnameBeta;
const config = genPublishConfigWithPublicPrivateHierarchies();
let config: StrictConfigV5;

beforeEach(() => {
config = genPublishConfigWithPublicPrivateHierarchies();
});

describe("AND WHEN noteref of published note", () => {
let resp: VFile;

describe("AND WHEN noteRef", () => {
describe("AND WHEN noteref of published note", () => {
let resp: VFile;
beforeAll(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you are seeing test issues is because beforeAll runs before beforeEach. you'll want to move the config initialization into the beforeAll block

await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname: fnameBeta,
linkText: `![[beta]]`,
});
},
{
preSetupHook: ENGINE_HOOKS.setupLinks,
expect,
}
);
});

test("THEN published note is rendered", async () => {
await verifyPublicNoteRef(resp, fnameBeta);
});
test("THEN private link in published note is hidden", async () => {
await verifyPrivateLink(resp, fnameAlpha);
});
});

describe("AND WHEN noteref of private note", () => {
let resp: VFile;
beforeAll(async () => {
await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname: fnameBeta,
linkText: `![[alpha]]`,
});
},
{
preSetupHook: ENGINE_HOOKS.setupLinks,
expect,
}
);
});
test("THEN private note is not rendered", async () => {
await verifyPrivateNoteRef(resp);
});
});

describe("AND WHEN wikilink", () => {
let resp: VFile;

test("THEN public link is rendered", async () => {
resp = await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname: fnameBeta,
linkText: `[[beta]] [[alpha]]`,
});
},
{
preSetupHook: ENGINE_HOOKS.setupLinks,
expect,
}
);
await verifyPublicLink(resp, fnameBeta);
});

describe("AND WHEN wikilink has an alias", () => {
beforeAll(async () => {
await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname,
linkText: `![[beta]]`,
fname: fnameBeta,
linkText: `[[Alpha|alpha]]`,
});
},
{
Expand All @@ -224,24 +305,42 @@ describe("GIVEN dendronPub", () => {
}
);
});
test("THEN published note is rendered", async () => {
await verifyPublicNoteRef(resp, fnameBeta);
describe("AND WHEN privateNoteBehavior config is aliasFallback", () => {
beforeAll(() => {
ConfigUtils.setPublishProp(
config,
"privateNoteBehavior",
"aliasFallback"
);
});
test("THEN a wikilink should be converted to a paragraph with the note alias as its text", async () => {
await verifyAlias(resp!, "Alpha");
});
});
test("THEN private link in published note is hidden", async () => {
await verifyPrivateLink(resp, fnameAlpha);

describe("AND WHEN privateNoteBehavior config is privateLink", () => {
beforeAll(() => {
ConfigUtils.setPublishProp(
config,
"privateNoteBehavior",
"privateLink"
);
});
test("THEN private link in published note is hidden", async () => {
await verifyPrivateLink(resp!, "Alpha");
});
});
});

describe("AND WHEN noteref of private note", () => {
let resp: VFile;
describe("AND WHNEN wikilink has no alias", () => {
beforeAll(async () => {
await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname,
linkText: `![[alpha]]`,
fname: fnameBeta,
linkText: `[[alpha]]`,
});
},
{
Expand All @@ -250,38 +349,12 @@ describe("GIVEN dendronPub", () => {
}
);
});
test("THEN private note is not rendered", async () => {
await verifyPrivateNoteRef(resp);
test("THEN private link in published note is hidden", async () => {
await verifyPrivateLink(resp!, "Alpha");
});
});
});

describe("AND WHEN wikilink", () => {
let resp: VFile;
beforeAll(async () => {
await runEngineTestV5(
async (opts) => {
resp = await createProc({
...opts,
config,
fname,
linkText: `[[beta]] [[alpha]]`,
});
},
{
preSetupHook: ENGINE_HOOKS.setupLinks,
expect,
}
);
});
test("THEN public link is rendered", async () => {
await verifyPublicLink(resp, fnameBeta);
});
test("THEN private link is hidden", async () => {
await verifyPrivateLink(resp, fnameAlpha);
});
});

describe("AND WHEN xvault link", () => {
let resp: VFile;
beforeAll(async () => {
Expand All @@ -291,7 +364,7 @@ describe("GIVEN dendronPub", () => {
resp = await createProc({
...opts,
config,
fname,
fname: fnameBeta,
linkText: `[[dendron://${vaultName}/beta]] [[dendron://${vaultName}/alpha]]`,
});
},
Expand Down
10 changes: 10 additions & 0 deletions packages/engine-test-utils/src/utils/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export class TestUnifiedUtils {
return checkString(contents, 'class="private"', value + " (Private)");
};

static verifyAlias = ({
contents,
value,
}: {
contents: string;
value: string;
}) => {
return checkString(contents, value);
};

/** Gets the descendent (child, or child of child...) node of a given node.
*
* @param node The root node to start descending from.
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-core/src/test/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class WorkspaceTestUtils {
enableRandomlyColoredTags: true,
enableTaskNotes: true,
enablePrettyLinks: true,
privateNoteBehavior: "privateLink",
},
};
if (duplicateNoteBehavior) {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-core/src/utils/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as queryString from "query-string";
import { ProgressLocation, QuickPickItem, Uri, window } from "vscode";
import { gdocRequiredScopes, GLOBAL_STATE } from "../constants";
import { StateService } from "../services/stateService";
import { GOOGLE_OAUTH_ID } from "../types/global";
import { clipboard } from "../utils";
import { VSCodeUtils } from "../vsCodeUtils";
import { getDWorkspace } from "../workspace";
Expand Down Expand Up @@ -44,7 +43,8 @@ export const launchGoogleOAuthFlow = async (id?: string) => {
);

const stringifiedParams = queryString.stringify({
client_id: GOOGLE_OAUTH_ID,
client_id:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not commit your google client id

"158580191802-mg09ec0cnahjrct3a6dtk1a6rpiq5rpj.apps.googleusercontent.com",
redirect_uri: `http://localhost:${port}/api/oauth/getToken?service=google&connectionId=${id}`,
scope: gdocRequiredScopes.join(" "), // space seperated string
response_type: "code",
Expand Down