prettify
This commit is contained in:
+31
-19
@@ -52,23 +52,35 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
|||||||
|
|
||||||
const body = lines.slice(bodyStartLineIndex).join("\n")
|
const body = lines.slice(bodyStartLineIndex).join("\n")
|
||||||
|
|
||||||
const filepath = fileURLToPath(fileUrl);
|
const filepath = fileURLToPath(fileUrl)
|
||||||
const filename = filepath.slice(filepath.lastIndexOf("/") + 1);
|
const filename = filepath.slice(filepath.lastIndexOf("/") + 1)
|
||||||
const slug =
|
const slug =
|
||||||
typeof data["slug"] === "string" ?
|
typeof data["slug"] === "string" ? data["slug"] : filename
|
||||||
data["slug"]
|
|
||||||
: filename;
|
|
||||||
|
|
||||||
data['title'] = data['title']
|
data["title"] =
|
||||||
?? lines.slice(bodyStartLineIndex).find(line => line.startsWith('# '))?.slice(2);
|
data["title"] ??
|
||||||
data['pubDate'] = data['pubDate']
|
lines
|
||||||
?? validDateOrUndefined(lines.slice(bodyStartLineIndex).find(line => line.startsWith('Published on: '))?.slice(14))
|
.slice(bodyStartLineIndex)
|
||||||
?? validDateOrUndefined(filename.replace(/\.[^.]\+$/, ''))
|
.find((line) => line.startsWith("# "))
|
||||||
?? validDateOrUndefined(slug.replace(/\.[^.]\+$/, ''));
|
?.slice(2)
|
||||||
data['updatedDate'] = data['updatedDate']
|
data["pubDate"] =
|
||||||
?? validDateOrUndefined(lines.slice(bodyStartLineIndex).find(line => line.startsWith('Updated on: '))?.slice(14))
|
data["pubDate"] ??
|
||||||
?? validDateOrUndefined(filename.replace(/\.[^.]\+$/, ''))
|
validDateOrUndefined(
|
||||||
?? validDateOrUndefined(slug.replace(/\.[^.]\+$/, ''));
|
lines
|
||||||
|
.slice(bodyStartLineIndex)
|
||||||
|
.find((line) => line.startsWith("Published on: "))
|
||||||
|
?.slice(14),
|
||||||
|
) ??
|
||||||
|
validDateOrUndefined(filename.replace(/\.[^.]\+$/, "")) ??
|
||||||
|
validDateOrUndefined(slug.replace(/\.[^.]\+$/, ""))
|
||||||
|
data["updatedDate"] =
|
||||||
|
data["updatedDate"] ??
|
||||||
|
validDateOrUndefined(
|
||||||
|
lines
|
||||||
|
.slice(bodyStartLineIndex)
|
||||||
|
.find((line) => line.startsWith("Updated on: "))
|
||||||
|
?.slice(14),
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
@@ -84,9 +96,9 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const validDateOrUndefined = (x: unknown) => {
|
const validDateOrUndefined = (x: unknown) => {
|
||||||
const d = new Date(x as string);
|
const d = new Date(x as string)
|
||||||
if (isNaN(d.valueOf())) {
|
if (isNaN(d.valueOf())) {
|
||||||
return undefined;
|
return undefined
|
||||||
|
}
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
return d;
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user