Skip to content

Commit 5d10789

Browse files
authored
Merge pull request #98 from sillsdev/RequireSlugs
feat: Add --require-slugs option
2 parents 5d00de3 + bff12fd commit 5d10789

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ One of the big attractions of Notion for large documentation projects is that yo
9090
9191
## Slugs
9292

93-
By default, pages will be given a slug based on the Notion id. For a human-readable URL, add a notion property named `Slug` to your database pages and enter a value in there that will work well in a URL. That is, no spaces, ?, #, /, etc.
93+
By default, pages will be given a slug based on the Notion ID. For a human-readable URL, add a notion property named `Slug` to your database pages and enter a value in there that will work well in a URL. That is, no spaces, ?, #, /, etc.
94+
95+
See `Options` to require slugs in Notion.
9496

9597
## Known Limitations
9698

@@ -130,7 +132,8 @@ Options:
130132
| -l, --log-level <level> | | Log level (choices: `info`, `verbose`, `debug`) |
131133
| -i, --img-output-path <string> | | Path to directory where images will be stored. If this is not included, images will be placed in the same directory as the document that uses them, which then allows for localization of screenshots. |
132134
| -p, --img-prefix-in-markdown <string> | | When referencing an image from markdown, prefix with this path instead of the full img-output-path. Should be used only in conjunction with --img-output-path. |
133-
| -h, --help | | display help for command |
135+
| --require-slugs | | If set, docu-notion will fail if any pages it would otherwise publish are missing a slug in Notion. |
136+
| -h, --help | | display help for command |
134137

135138
# Plugins
136139

Diff for: src/pull.ts

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type DocuNotionOptions = {
3939
imgOutputPath: string;
4040
imgPrefixInMarkdown: string;
4141
statusTag: string;
42+
requireSlugs?: boolean;
4243
};
4344

4445
let layoutStrategy: LayoutStrategy;
@@ -49,6 +50,7 @@ const counts = {
4950
skipped_because_empty: 0,
5051
skipped_because_status: 0,
5152
skipped_because_level_cannot_have_content: 0,
53+
error_because_no_slug: 0,
5254
};
5355

5456
export async function notionPull(options: DocuNotionOptions): Promise<void> {
@@ -156,11 +158,20 @@ async function outputPages(
156158
);
157159
++context.counts.skipped_because_status;
158160
} else {
161+
if (options.requireSlugs && !page.hasExplicitSlug) {
162+
error(
163+
`Page "${page.nameOrTitle}" is missing a required slug. (--require-slugs is set.)`
164+
);
165+
++counts.error_because_no_slug;
166+
}
167+
159168
const markdown = await getMarkdownForPage(config, context, page);
160169
writePage(page, markdown);
161170
}
162171
}
163172

173+
if (counts.error_because_no_slug > 0) exit(1);
174+
164175
info(`Finished processing ${pages.length} pages`);
165176
info(JSON.stringify(counts));
166177
}

Diff for: src/run.ts

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export async function run(): Promise<void> {
5656
.option(
5757
"-p, --img-prefix-in-markdown <string>",
5858
"When referencing an image from markdown, prefix with this path instead of the full img-output-path. Should be used only in conjunction with --img-output-path."
59+
)
60+
.option(
61+
"--require-slugs",
62+
"If set, docu-notion will fail if any pages it would otherwise publish are missing a slug in Notion.",
63+
false
5964
);
6065

6166
program.showHelpAfterError();

0 commit comments

Comments
 (0)