Skip to content

Commit

Permalink
refactor: remove equation formatter in favour of
Browse files Browse the repository at this point in the history
  • Loading branch information
HEIGE-PCloud committed May 2, 2024
1 parent 5f4026b commit 2987005
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 72 deletions.
17 changes: 0 additions & 17 deletions notion-hugo.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ const userConfig: UserConfig = {
target_folder: '.'
}
],
},
formatter: {
equation: {
// config how maths equations are rendered into markdown
// there are three options (markdown, shortcode, html)
// the markdown option renders the equations in default markdown flavor:
// \(inline equation\) \[displayed equation\]
// the shortcode option renders the equations into the math shortcode
// which relies on your Hugo theme to support and render the equations
// the html option directly renders equations into HTML + MathML
// when converting your Notion page into the markdown file,
// it makes the markdown file a lot less readable but it works for all themes.
// `markup.goldmark.renderer.unsafe` needs to be set to true for the HTML tags to work,
// which is the default setting.
// https://gohugo.io/getting-started/configuration-markup///configure-markup
style: 'html'
}
}
}

Expand Down
22 changes: 0 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ export type Mount = {
pages: PageMount[];
};

export type EquationFormatter = {
style: "markdown" | "shortcode" | "html";
};

export type Formatter = {
equation: EquationFormatter;
};

export type Config = {
mount: Mount;
formatter: Formatter;
};

export async function loadConfig(): Promise<Config> {
Expand All @@ -36,11 +27,6 @@ export async function loadConfig(): Promise<Config> {
mount: {
databases: [],
pages: []
},
formatter: {
equation: {
style: 'html'
}
}
}
// configure mount settings
Expand Down Expand Up @@ -78,9 +64,6 @@ export async function loadConfig(): Promise<Config> {
}
}

// configure formatter settings
if (userConfig.formatter?.equation) config.formatter.equation = userConfig.formatter.equation

return config;
}

Expand All @@ -91,13 +74,8 @@ export type UserMount = {
pages?: PageMount[];
}

export type UserFormatter = {
equation?: EquationFormatter;
}

export type UserConfig = {
mount: UserMount
formatter?: UserFormatter
}

export function defineConfig(config: UserConfig) {
Expand Down
33 changes: 0 additions & 33 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,11 @@ function getExpiryTime(blocks: MdBlock[], expiry_time: string | undefined = unde
export async function renderPage(page: PageObjectResponse, notion: Client) {

// load formatter config
const formatterConfig = (await loadConfig()).formatter;
formatterConfig.equation.style

const n2m = new NotionToMarkdown({ notionClient: notion });
n2m.setUnsupportedTransformer((type) => {
return `{{< notion-unsupported-block type=${type} >}}`
})
let frontInjectString = ''

switch (formatterConfig.equation.style) {
case 'markdown':
n2m.setCustomTransformer("equation", async (block) => {
const { equation } = block as EquationBlockObjectResponse;
return `\\[${equation}\\]`;
});
break;
case 'shortcode':
n2m.setCustomTransformer("equation", async (block) => {
const { equation } = block as EquationBlockObjectResponse;
return `{{< math >}}\\[${equation}\\]{{< /math >}}`
})
break;
case 'html':
n2m.setCustomTransformer("equation", async (block) => {
const { equation } = block as EquationBlockObjectResponse;
const html = katex.renderToString(equation.expression, {
throwOnError: false,
displayMode: true,
});
return html;
});
frontInjectString += `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/katex.min.css" integrity="sha384-bYdxxUwYipFNohQlHt0bjN/LCpueqWz13HufFEV1SUatKs1cm4L6fFgCi1jT643X" crossorigin="anonymous">\n`
break
default:
console.warn('[Warn] invalid notion.toml config')
break;
}

let nearest_expiry_time: string | null = null
const mdblocks = await n2m.pageToMarkdown(page.id);
const page_expiry_time = getExpiryTime(mdblocks)
Expand Down

0 comments on commit 2987005

Please sign in to comment.