Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/www.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
staticalize-linux \
--site=http://127.0.0.1:8000 \
--output=www/built \
--base=https://effection-www.deno.dev/
--base=https://effection.deno.dev

- run: npx pagefind --site built
working-directory: ./www
Expand Down
6 changes: 3 additions & 3 deletions www/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { main, suspend } from "effection";
import { createRevolution, ServerInfo } from "revolution";

import { etagPlugin } from "./plugins/etag.ts";
import { rebasePlugin } from "./plugins/rebase.ts";
import { route, sitemapPlugin } from "./plugins/sitemap.ts";
import { tailwindPlugin } from "./plugins/tailwind.ts";

Expand All @@ -13,7 +12,7 @@ import { indexRoute } from "./routes/index-route.tsx";
import { xIndexRedirect, xIndexRoute } from "./routes/x-index-route.tsx";
import { xPackageRedirect, xPackageRoute } from "./routes/x-package-route.tsx";

import { initConfig, useConfig } from "./context/config.ts";
import { useConfig } from "./context/config.ts";
import { initFetch } from "./context/fetch.ts";
import { initJSRClient } from "./context/jsr.ts";
import { initWorktrees } from "./lib/worktrees.ts";
Expand All @@ -25,6 +24,7 @@ import { redirectIndexRoute } from "./routes/redirect-index-route.tsx";
import { searchRoute } from "./routes/search-route.tsx";
import { initClones } from "./lib/clones.ts";
import { initOctokitContext } from "./lib/octokit.ts";
import { currentRequestPlugin } from "./plugins/current-request.ts";

// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
if (import.meta.main) {
Expand Down Expand Up @@ -70,8 +70,8 @@ if (import.meta.main) {
],
plugins: [
yield* tailwindPlugin({ input: "main.css", outdir: "tailwind" }),
currentRequestPlugin(),
etagPlugin(),
rebasePlugin(),
sitemapPlugin(),
],
});
Expand Down
51 changes: 51 additions & 0 deletions www/plugins/current-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { RevolutionPlugin } from "revolution";
import { posixNormalize } from "_posixNormalize";
import { type Operation } from "effection";
import { CurrentRequest } from "../context/request.ts";

export function currentRequestPlugin(): RevolutionPlugin {
return {
*http(request, next) {
yield* CurrentRequest.set(request);
return yield* next(request);
}
}
}

/**
* Convert a non fully qualified url into a fully qualified url, complete
* with protocol.
*/
export function* useAbsoluteUrl(path: string = "/"): Operation<string> {
let absolute = yield* useAbsoluteUrlFactory();

return absolute(path);
}

export function* useAbsoluteUrlFactory(): Operation<(path: string) => string> {
let request = yield* CurrentRequest.expect()

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

/**
* Get the canonical url for the current path.
*/
export function* useCanonicalUrl(options: { base: string; }): Operation<string> {
let request = yield* CurrentRequest.expect()

let req = new URL(request.url);
let url = new URL(options.base);
url.pathname = `${url.pathname}${req.pathname}`;
return String(url);
}
96 changes: 0 additions & 96 deletions www/plugins/rebase.ts

This file was deleted.

2 changes: 1 addition & 1 deletion www/plugins/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { route as revolutionRoute, useRevolutionOptions } from "revolution";
import type { Operation } from "effection";
import { stringify } from "@libs/xml";
import { compile } from "path-to-regexp";
import { useAbsoluteUrlFactory } from "./rebase.ts";
import { useAbsoluteUrlFactory } from "./current-request.ts";

export function sitemapPlugin(): RevolutionPlugin {
return {
Expand Down
11 changes: 5 additions & 6 deletions www/routes/app.html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { JSXChild } from "revolution";

import { Footer } from "../components/footer.tsx";
import { Header, type HeaderProps } from "../components/header.tsx";
import { useAbsoluteUrl, useCanonicalUrl } from "../plugins/rebase.ts";
import { useAbsoluteUrl, useCanonicalUrl } from "../plugins/current-request.ts";
import { JSXElement } from "revolution/jsx-runtime";

export type Options = {
Expand All @@ -26,7 +26,6 @@ export function* useAppHtml({
let twitterImageURL = yield* useAbsoluteUrl(
"/assets/images/meta-effection.png",
);
let homeURL = yield* useAbsoluteUrl("/");

let canonicalURL = yield* useCanonicalUrl({ base: "https://frontside.com/effection" });

Expand All @@ -37,17 +36,17 @@ export function* useAppHtml({
<head>
<meta charset="UTF-8" />
<title>{title}</title>
<meta property="og:image" content="/assets/images/meta-effection.png" />
<meta property="og:image" content={twitterImageURL} />
<meta property="og:title" content={title} data-rh="true" />
<meta property="og:url" content={homeURL} />
<meta property="og:url" content={canonicalURL} />
<meta property="og:description" content={description} />
<meta name="description" content={description} />
<meta name="twitter:image" content={twitterImageURL} />
<link rel="icon" href="/assets/images/favicon-effection.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="canonical" href={canonicalURL} />
<link rel="alternate" href={homeURL} hreflang="en" />
<link rel="alternate" href={homeURL} hreflang="x-default" />
<link rel="alternate" href={canonicalURL} hreflang="en" />
<link rel="alternate" href={canonicalURL} hreflang="x-default" />
<link
href="/assets/prism-atom-one-dark.css"
rel="preload"
Expand Down
Loading