Skip to content

Commit

Permalink
feat: For Markdown files names, use explicit slugs when available
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Oct 6, 2022
1 parent 2d4551e commit b276f87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/HierarchicalNamedLayoutStrategy.ts
Expand Up @@ -32,13 +32,20 @@ export class HierarchicalNamedLayoutStrategy extends LayoutStrategy {
"/" +
page.context +
"/" +
sanitize(page.nameOrTitle) +
sanitize(page.nameForFile()) +
extensionWithDot;

path = path
.replaceAll("//", "/")
.replaceAll("%20", "-")
.replaceAll(" ", "-");
.replaceAll(" ", "-")
// crowdin complains about some characters in file names. I haven't found
// the actual list, so these are from memory.
.replaceAll('"', "")
.replaceAll("“", "")
.replaceAll("”", "")
.replaceAll("'", "")
.replaceAll("?", "-");
// console.log(
// `getPathForPage(${context}, ${pageId}, ${title}) with root ${this.rootDirectory} --> ${path}`
// );
Expand Down
9 changes: 9 additions & 0 deletions src/NotionPage.ts
Expand Up @@ -90,6 +90,15 @@ export class NotionPage {
return this.type === PageType.DatabasePage ? this.name : this.title;
}

public nameForFile(): string {
// In Notion, pages from the Database have names and simple pages have titles.
return this.type === PageType.Simple
? this.title
: // if it's a Database page, then we'll use the slug unless there is none, then we'd rather have the
// page name than an ugly id for the file name
this.explicitSlug()?.replace(/^\//, "") || this.name;
}

// TODO: let's go farther in hiding this separate title vs name stuff. This seems like an implementation detail on the Notion side.

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

0 comments on commit b276f87

Please sign in to comment.