summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-03-24 21:24:22 +0000
committerJoe Carstairs <me@joeac.net>2026-03-24 21:24:22 +0000
commit73bd05f6507fa6bab3a1d452dbf264f7c7bc5cf7 (patch)
tree366cc993c6ade09b0c110f2914bcdec8df17b191
parentf909e1adc934b26dd02009e8d075f5c7e201b2cc (diff)
prettify
-rw-r--r--src/index.ts56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/index.ts b/src/index.ts
index 7a7eb96..85e57db 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -52,23 +52,35 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
const body = lines.slice(bodyStartLineIndex).join("\n")
- const filepath = fileURLToPath(fileUrl);
- const filename = filepath.slice(filepath.lastIndexOf("/") + 1);
- const slug =
- typeof data["slug"] === "string" ?
- data["slug"]
- : filename;
+ const filepath = fileURLToPath(fileUrl)
+ const filename = filepath.slice(filepath.lastIndexOf("/") + 1)
+ const slug =
+ 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),
+ )
return {
data,
@@ -84,9 +96,9 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
}
const validDateOrUndefined = (x: unknown) => {
- const d = new Date(x as string);
- if (isNaN(d.valueOf())) {
- return undefined;
- }
- return d;
-};
+ const d = new Date(x as string)
+ if (isNaN(d.valueOf())) {
+ return undefined
+ }
+ return d
+}