Refactor footnotes transformer for improved localization handling

- Cleaned up code formatting for better readability.
- Ensured proper localization of footnote titles by replacing text nodes with localized values.
- Removed unnecessary class names from headings to enhance accessibility.
This commit is contained in:
Amir Pourmand 2025-08-24 17:12:04 +03:30
parent 09b4f072be
commit e23c03ca25

View File

@ -17,20 +17,20 @@ export const LocalizedFootnotes: QuartzTransformerPlugin = () => {
// Find footnotes section
if (node.tagName === "section" && node.properties?.["dataFootnotes"] !== undefined) {
// Find the h2 heading inside
const heading = node.children.find(child =>
child.type === "element" && child.tagName === "h2"
const heading = node.children.find(
(child) => child.type === "element" && child.tagName === "h2",
) as Element
if (heading) {
// Remove sr-only class if present
if (Array.isArray(heading.properties?.className)) {
heading.properties.className = heading.properties.className.filter(
cls => cls !== "sr-only"
(cls) => cls !== "sr-only",
)
}
// Replace the first text node with localized text
const textNode = heading.children.find(child => child.type === "text")
const textNode = heading.children.find((child) => child.type === "text")
if (textNode) {
textNode.value = locale.components.footnotes.title
}