Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add sitemap.xml to website #910

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions www/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tasks": {
"dev": "deno run -A lib/watch.ts components docs lib plugins routes -- deno run -A --lock-write main.tsx"
"dev": "deno run -A lib/watch.ts components docs lib plugins routes -- deno run -A main.tsx"
},
"lint": {
"exclude": ["docs/esm"],
Expand All @@ -17,8 +17,8 @@
"jsxImportSource": "revolution"
},
"imports": {
"effection": "https://deno.land/x/[email protected].0-beta.2/mod.ts",
"revolution": "https://deno.land/x/revolution@0.5.2/mod.ts",
"revolution/jsx-runtime": "https://deno.land/x/revolution@0.5.2/jsx-runtime.ts"
"effection": "https://deno.land/x/[email protected].3/mod.ts",
"revolution": "https://deno.land/x/revolution@0.6.0/mod.ts",
"revolution/jsx-runtime": "https://deno.land/x/revolution@0.6.0/jsx-runtime.ts"
}
}
31 changes: 30 additions & 1 deletion www/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions www/docs/docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { call, type Operation, resource, type Task, useScope } from "effection";
import structure from "./structure.json" assert { type: "json" };
import {
all,
call,
type Operation,
resource,
type Task,
useScope,
} from "effection";
import structure from "./structure.json" with { type: "json" };

import { basename } from "https://deno.land/[email protected]/path/posix/basename.ts";

Expand All @@ -19,6 +26,7 @@ export interface DocModule {
}

export interface Docs {
all(): Operation<Doc[]>;
getDoc(id?: string): Operation<Doc | undefined>;
}

Expand Down Expand Up @@ -102,6 +110,12 @@ export function loadDocs(): Operation<Docs> {
}

yield* provide({
*all() {
if (!loaders) {
loaders = yield* load();
}
return yield* all([...loaders.values()]);
},
*getDoc(id) {
if (id) {
if (!loaders) {
Expand Down
74 changes: 29 additions & 45 deletions www/lib/watch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
action,
filter,
first,
pipe,
call,
main,
resource,
run,
sleep,
type Stream,
stream,
Expand All @@ -15,7 +12,7 @@ import { parse } from "https://deno.land/[email protected]/flags/mod.ts";

import { useCommand } from "./use-command.ts";

await run(function* () {
await main(function* () {
let scriptargs = parse(Deno.args, {
"--": true,
});
Expand All @@ -28,49 +25,36 @@ await run(function* () {
console.log(`watch: ${JSON.stringify(paths)}`);
console.log(`run: ${cmd} ${args.join(" ")}`);

yield* action<void>(function* (resolve) {
Deno.addSignalListener("SIGINT", resolve);
try {
while (true) {
yield* action(function* (restart) {
let change = pipe(
useFsWatch(paths),
filter(function* (event) {
return !event.paths.some((path) =>
ignores.some((ignore) => path.includes(ignore))
);
}),
);

yield* useCommand(cmd, { args });

yield* first(change);
while (true) {
yield* call(function* () {
let changes = yield* useFsWatch(paths);

yield* sleep(100);
yield* useCommand(cmd, { args });

console.log("changes detected, restarting...");

restart();
});
while (true) {
let { value: change } = yield* changes.next();
if (
!change.paths.some((path) =>
ignores.some((ignore) => path.includes(ignore))
)
) {
break;
}
}
} finally {
Deno.removeSignalListener("SIGINT", resolve);
}
});
yield* sleep(100);
console.log("changes detected, restarting...");
});
}
});

function useFsWatch(paths: string | string[]): Stream<Deno.FsEvent, never> {
return {
subscribe() {
return resource(function* (provide) {
let watcher = Deno.watchFs(paths);
try {
let subscription = yield* stream(watcher).subscribe();
yield* provide(subscription as Subscription<Deno.FsEvent, never>);
} finally {
watcher.close();
}
});
},
};
return resource(function* (provide) {
let watcher = Deno.watchFs(paths);
try {
let subscription = yield* stream(watcher);
yield* provide(subscription as Subscription<Deno.FsEvent, never>);
} finally {
watcher.close();
}
});
}
4 changes: 3 additions & 1 deletion www/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { main, suspend } from "effection";

import { createRevolution, route } from "revolution";
import { createRevolution } from "revolution";
import { docsRoute } from "./routes/docs-route.tsx";
import { indexRoute } from "./routes/index-route.tsx";
import { v2docsRoute } from "./routes/v2docs-route.tsx";
Expand All @@ -11,6 +11,7 @@ import { config } from "./tailwind.config.ts";
import { twindPlugin } from "./plugins/twind.ts";
import { rebasePlugin } from "./plugins/rebase.ts";
import { etagPlugin } from "./plugins/etag.ts";
import { route, sitemapPlugin } from "./plugins/sitemap.ts";

import { loadDocs } from "./docs/docs.ts";
import { loadV2Docs } from "./docs/v2-docs.ts";
Expand All @@ -34,6 +35,7 @@ await main(function* () {
twindPlugin({ config }),
etagPlugin(),
rebasePlugin(),
sitemapPlugin(),
],
});

Expand Down
26 changes: 17 additions & 9 deletions www/plugins/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ export function rebasePlugin(): RevolutionPlugin {
* with protocol.
*/
export function* useAbsoluteUrl(path: string): Operation<string> {
let normalizedPath = posixNormalize(path);
if (normalizedPath.startsWith("/")) {
let base = yield* BaseUrl;
let url = new URL(base);
url.pathname = posixNormalize(`${base.pathname}${path}`);
return url.toString();
} else {
let request = yield* CurrentRequest;
return new URL(path, request.url).toString();
let absolute = yield* useAbsoluteUrlFactory();
return absolute(path);
}

export function* useAbsoluteUrlFactory(): Operation<(path: string) => string> {
let base = yield* BaseUrl;
let request = yield* CurrentRequest;

return (path) => {
let normalizedPath = posixNormalize(path);
if (normalizedPath.startsWith("/")) {
let url = new URL(base);
url.pathname = posixNormalize(`${base.pathname}${path}`);
return url.toString();
} else {
return new URL(path, request.url).toString();
}
}
}
Loading
Loading