Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F48
rehype-title.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
519 B
Referenced Files
None
Subscribers
None
rehype-title.ts
View Options
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
Details
Attached
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)
Attached To
Mode
rB blog
Attached
Detach File
Event Timeline