Compare commits
6 Commits
f909e1adc9
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ab32140ae2 | |||
| c7aad8cd26 | |||
| a79d485c93 | |||
| 5c27d9c0ea | |||
| 2048c576e9 | |||
| 73bd05f650 |
+37
-20
@@ -50,25 +50,42 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
||||
}
|
||||
}
|
||||
|
||||
const body = lines.slice(bodyStartLineIndex).join("\n")
|
||||
let body = lines.slice(bodyStartLineIndex).join("\n")
|
||||
|
||||
const filepath = fileURLToPath(fileUrl);
|
||||
const filename = filepath.slice(filepath.lastIndexOf("/") + 1);
|
||||
const filepath = fileURLToPath(fileUrl)
|
||||
const filename = filepath.slice(filepath.lastIndexOf("/") + 1)
|
||||
const slug =
|
||||
typeof data["slug"] === "string" ?
|
||||
data["slug"]
|
||||
: filename;
|
||||
typeof data["slug"] === "string" ? data["slug"] : filename
|
||||
|
||||
data['title'] = data['title']
|
||||
?? lines.slice(bodyStartLineIndex).find(line => line.startsWith('# '))?.slice(2);
|
||||
data['pubDate'] = data['pubDate']
|
||||
?? validDateOrUndefined(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))
|
||||
?? validDateOrUndefined(filename.replace(/\.[^.]\+$/, ''))
|
||||
?? validDateOrUndefined(slug.replace(/\.[^.]\+$/, ''));
|
||||
data["title"] =
|
||||
data["title"] ??
|
||||
lines
|
||||
.slice(bodyStartLineIndex)
|
||||
.find((line) => line.startsWith("# "))
|
||||
?.slice(2)
|
||||
data["pubDate"] =
|
||||
data["pubDate"] ??
|
||||
validDateOrUndefined(
|
||||
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),
|
||||
)
|
||||
|
||||
if (data["title"]) {
|
||||
body.replace(`# ${data["title"]}\n`, '');
|
||||
body = body.trim();
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
@@ -84,9 +101,9 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
||||
}
|
||||
|
||||
const validDateOrUndefined = (x: unknown) => {
|
||||
const d = new Date(x as string);
|
||||
const d = new Date(x as string)
|
||||
if (isNaN(d.valueOf())) {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
return d;
|
||||
};
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user