Page MenuHomePhorge

rehype-title.ts
No OneTemporary

Authored By
Unknown
Size
519 B
Referenced Files
None
Subscribers
None

rehype-title.ts

import type { Root } from "npm:@types/hast";
import type { VFile } from "vfile";
import { SKIP, visit } from "unist-util-visit";
import { toString } from "hast-util-to-string";
export default function rehypeTitle() {
return function (tree: Root, file: VFile) {
visit(tree, "element", function (node, index, parent) {
if (node.tagName === "h1" && !file.data.title) {
file.data.title = toString(node);
parent!.children.splice(index!, 1);
return [SKIP, index];
}
});
};
}

File Metadata

Mime Type
application/javascript
Expires
Sun, Oct 25, 01:37 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32
Default Alt Text
rehype-title.ts (519 B)

Event Timeline