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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
```

このワークスペースではまだ本番配信・GitHubリポジトリ作成を行っていない。
Prismtone、Accountsへの外部リンク先の公開状態は未検証。
配信は Cloudflare Pages。本番ブランチは `main`、ビルドコマンドは `npm run build`、出力は `dist`。

Accounts を一般に開くまでは、ビルドがログインとアカウント管理の入口 (`data-accounts-entry`) を `hidden` にし、
`lumorphia-accounts-origin` を空にして `account.js` がセッションを見に行かないようにする。
開くときは Pages の環境変数 `LUMORPHIA_ACCOUNTS_OPEN=1` を設定してビルドし直す。
`npm run dev` はビルドを通さないので、手元と Accounts の E2E では入口が常に見える。

## デザイン・素材

Expand Down
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
><a
class="account-link"
id="account-login"
data-accounts-entry
href="https://accounts.lumorphia.com/login"
>ログイン
<svg
Expand Down Expand Up @@ -288,7 +289,10 @@ <h2 id="account-title">いつもの自分で、それぞれの場所へ。</h2>
プロフィールとログインは、Lumorphia アカウントで。<br />各サービスで使う名前やアイコン、キャラクター情報をまとめて管理します。
</p>
</div>
<a class="outline" href="https://accounts.lumorphia.com/settings"
<a
class="outline"
href="https://accounts.lumorphia.com/settings"
data-accounts-entry
>アカウントを管理
<svg
class="external-link-icon"
Expand Down Expand Up @@ -319,7 +323,7 @@ <h2 id="account-title">いつもの自分で、それぞれの場所へ。</h2>
>
<nav aria-label="フッターナビゲーション">
<a href="#services">サービス</a
><a href="https://accounts.lumorphia.com/settings"
><a href="https://accounts.lumorphia.com/settings" data-accounts-entry
>アカウント
<svg
class="external-link-icon"
Expand Down
21 changes: 19 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,20 @@ function headersFor(versioned) {
];
return `${lines.join("\n")}\n`;
}
export async function build(destination = output) {
/**
* accounts を開くまでは、ログインと管理の入口 (data-accounts-entry) を隠し、
* account.js がセッションを見に行かないよう accounts の origin を空にする。
*/
function gateAccounts(html, accountsOpen) {
if (accountsOpen) return html;
return html
.replaceAll("data-accounts-entry", "data-accounts-entry hidden")
.replace(
/(name="lumorphia-accounts-origin"\s+content=)"[^"]*"/,
'$1""',
);
}
export async function build(destination = output, { accountsOpen = false } = {}) {
await mkdir(destination, { recursive: true });
await mkdir(path.join(destination, "assets"), { recursive: true });
const filenames = new Map();
Expand All @@ -55,6 +68,7 @@ export async function build(destination = output) {
let html = await readFile(path.join(root, name), "utf8");
for (const [original, versioned] of filenames)
html = html.replaceAll(original, versioned);
html = gateAccounts(html, accountsOpen);
await writeFile(path.join(destination, name), html);
}
await writeFile(path.join(destination, "_headers"), headersFor([...filenames.values()]));
Expand All @@ -71,7 +85,10 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
const staging = path.join(root, ".dist-staging");
try {
await rm(staging, { recursive: true, force: true });
await build(staging);
// Cloudflare Pages の環境変数。accounts を開くときに 1 にしてビルドし直す
await build(staging, {
accountsOpen: process.env.LUMORPHIA_ACCOUNTS_OPEN === "1",
});
await rm(output, { recursive: true, force: true });
await rename(staging, output);
console.log("Built dist/ for https://lumorphia.com/");
Expand Down
32 changes: 32 additions & 0 deletions tests/build.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,35 @@ test("writes the security and cache headers for Cloudflare Pages", async () => {
await rm(output, { recursive: true, force: true });
}
});

// accounts を開くまでは、ログインと管理の入口を出さず、セッションも見に行かない
test("hides the account entries until accounts opens", async () => {
const output = await mkdtemp(path.join(os.tmpdir(), "lumorphia-build-"));
try {
await build(output);
const html = await readFile(path.join(output, "index.html"), "utf8");
const entries = [...html.matchAll(/<[a-z]+[^>]*data-accounts-entry[^>]*>/g)];
assert.equal(entries.length, 3);
for (const [tag] of entries) assert.match(tag, /\shidden(?=[\s>])/);
assert.match(html, /name="lumorphia-accounts-origin"\s+content=""/);
} finally {
await rm(output, { recursive: true, force: true });
}
});

test("shows the account entries when accounts is open", async () => {
const output = await mkdtemp(path.join(os.tmpdir(), "lumorphia-build-"));
try {
await build(output, { accountsOpen: true });
const html = await readFile(path.join(output, "index.html"), "utf8");
const entries = [...html.matchAll(/<[a-z]+[^>]*data-accounts-entry[^>]*>/g)];
assert.equal(entries.length, 3);
for (const [tag] of entries) assert.doesNotMatch(tag, /\shidden(?=[\s>])/);
assert.match(
html,
/name="lumorphia-accounts-origin"\s+content="https:\/\/accounts\.lumorphia\.com"/,
);
} finally {
await rm(output, { recursive: true, force: true });
}
});
Loading