Skip to content

Commit b276f87

Browse files
committed
feat: For Markdown files names, use explicit slugs when available
1 parent 2d4551e commit b276f87

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/HierarchicalNamedLayoutStrategy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ export class HierarchicalNamedLayoutStrategy extends LayoutStrategy {
3232
"/" +
3333
page.context +
3434
"/" +
35-
sanitize(page.nameOrTitle) +
35+
sanitize(page.nameForFile()) +
3636
extensionWithDot;
3737

3838
path = path
3939
.replaceAll("//", "/")
4040
.replaceAll("%20", "-")
41-
.replaceAll(" ", "-");
41+
.replaceAll(" ", "-")
42+
// crowdin complains about some characters in file names. I haven't found
43+
// the actual list, so these are from memory.
44+
.replaceAll('"', "")
45+
.replaceAll("“", "")
46+
.replaceAll("”", "")
47+
.replaceAll("'", "")
48+
.replaceAll("?", "-");
4249
// console.log(
4350
// `getPathForPage(${context}, ${pageId}, ${title}) with root ${this.rootDirectory} --> ${path}`
4451
// );

src/NotionPage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ export class NotionPage {
9090
return this.type === PageType.DatabasePage ? this.name : this.title;
9191
}
9292

93+
public nameForFile(): string {
94+
// In Notion, pages from the Database have names and simple pages have titles.
95+
return this.type === PageType.Simple
96+
? this.title
97+
: // if it's a Database page, then we'll use the slug unless there is none, then we'd rather have the
98+
// page name than an ugly id for the file name
99+
this.explicitSlug()?.replace(/^\//, "") || this.name;
100+
}
101+
93102
// TODO: let's go farther in hiding this separate title vs name stuff. This seems like an implementation detail on the Notion side.
94103

95104
// In Notion, pages from the Outline have "title"'s.

0 commit comments

Comments
 (0)