Skip to content

Commit dd869b5

Browse files
authored
Merge pull request #13 from notangelmario/deps-file
Added a deps file
2 parents 8c8fc73 + a25d31c commit dd869b5

File tree

7 files changed

+21
-25
lines changed

7 files changed

+21
-25
lines changed

deno.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"tasks": {
33
"test": "deno test --allow-env --allow-write --allow-read"
4-
},
5-
"importMap": "./import_map.json"
4+
}
65
}

import_map.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { join, resolve } from "https://deno.land/[email protected]/path/mod.ts";
2-
import { ensureFile } from "https://deno.land/[email protected]/fs/mod.ts";
1+
import { join, resolve, ensureFile } from "./src/deps.ts";
32

43
const routesDirectory = resolve("./routes");
54

src/deps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default as day} from "https://esm.sh/[email protected]";
2+
export { basename, extname, join, resolve } from "https://deno.land/[email protected]/path/mod.ts";
3+
export { assert, assertStringIncludes, assertThrows } from "https://deno.land/[email protected]/testing/asserts.ts";
4+
export { FakeTime } from "https://deno.land/[email protected]/testing/time.ts";
5+
export { ensureFile } from "https://deno.land/[email protected]/fs/mod.ts";

src/sitemap.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
/// <reference lib="deno.ns" />
55
/// <reference lib="deno.unstable" />
66

7-
import day from "dayjs";
8-
import { basename, extname } from "path";
9-
import { Manifest } from "fresh/server.ts";
7+
import { basename, extname, day } from "./deps.ts";
8+
import { type Manifest } from "./types.ts";
109

1110
export class SitemapContext {
1211
#url: string;
@@ -46,7 +45,7 @@ export class SitemapContext {
4645
}
4746

4847
add(route: string) {
49-
this.#routes.push(route);
48+
this.#routes.push(route.replace(/(^\/?)|(\/?$)/, '/'));
5049
return this;
5150
}
5251

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// deno-lint-ignore-file no-explicit-any
2+
3+
export interface Manifest {
4+
routes: Record<string,any>;
5+
islands: Record<string, any>;
6+
baseUrl: string;
7+
}

tests/sitemap.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { SitemapContext } from "../mod.ts";
2-
import { assert, assertStringIncludes, assertThrows } from "testing/asserts.ts";
3-
import { FakeTime } from "testing/time.ts";
4-
import { Manifest } from "fresh/server.ts";
2+
import { assert, assertStringIncludes, assertThrows, FakeTime } from "../src/deps.ts";
3+
import { Manifest } from "../src/types.ts";
54

65
const url = "https://deno.land";
76
Deno.env.set("APP_URL", url);
@@ -165,7 +164,7 @@ Deno.test("Add additional routes", () => {
165164
};
166165
const sitemap = new SitemapContext(url, manifest);
167166

168-
const result = sitemap.add("/blog/hello-world").generate();
167+
const result = sitemap.add("/blog/hello-world").add("help").generate();
169168

170169
assertStringIncludes(result, '<?xml version="1.0" encoding="UTF-8"?>');
171170
assertStringIncludes(
@@ -174,6 +173,7 @@ Deno.test("Add additional routes", () => {
174173
);
175174

176175
assertStringIncludes(result, "<loc>https://deno.land/blog/hello-world</loc>");
176+
assertStringIncludes(result, "<loc>https://deno.land/help</loc>");
177177

178178
assertStringIncludes(result, "</urlset>");
179179
});

0 commit comments

Comments
 (0)