@tideworthy/tidysites-platform 0.10.11 → 0.10.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/middleware.ts +29 -5
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.12
|
|
4
|
+
|
|
5
|
+
- The staging site is never indexed: every response carries `X-Robots-Tag: noindex, nofollow`, robots.txt disallows everything and the sitemap answers 404. The publish crawl still gets the real robots.txt and sitemap for the live copy.
|
|
6
|
+
|
|
3
7
|
## 0.10.11
|
|
4
8
|
|
|
5
9
|
- Editor bar: Request a change comes first and carries the blue; Edit follows it plain.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tideworthy/tidysites-platform",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.12",
|
|
4
4
|
"description": "The Tidysites platform integration for EmDash sites: bootstrap, sessions, maintenance, health, and publish hooks under /_tidy/*.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/middleware.ts
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Astro middleware registered by tidyPlatform(): the framing policy from
|
|
3
|
+
* TIDY_FRAME_ANCESTORS, and no indexing of the staging site. This worker is
|
|
4
|
+
* the staging site (the live site is a static copy served by its own small
|
|
5
|
+
* worker), so every answer here carries noindex, robots.txt disallows
|
|
6
|
+
* everything and the sitemap is gone. The publish crawl identifies itself
|
|
7
|
+
* and gets the real robots.txt and sitemap, which is what the live copy
|
|
8
|
+
* ships.
|
|
9
|
+
*/
|
|
2
10
|
import type { MiddlewareHandler } from "astro";
|
|
3
11
|
import { workerEnv } from "./lib/env";
|
|
4
12
|
import { applyFramePolicy, frameAncestors } from "./lib/frame";
|
|
5
13
|
|
|
6
|
-
|
|
14
|
+
const PUBLISH_CRAWL = "tidysites-publish";
|
|
15
|
+
const NOINDEX = "noindex, nofollow";
|
|
16
|
+
|
|
17
|
+
export const onRequest: MiddlewareHandler = async (context, next) => {
|
|
18
|
+
const crawl = context.request.headers.get("user-agent") === PUBLISH_CRAWL;
|
|
19
|
+
if (!crawl) {
|
|
20
|
+
const path = context.url.pathname;
|
|
21
|
+
if (path === "/robots.txt") {
|
|
22
|
+
return new Response("User-agent: *\nDisallow: /\n", { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store", "x-robots-tag": NOINDEX } });
|
|
23
|
+
}
|
|
24
|
+
if (path === "/sitemap.xml" || path === "/sitemap-index.xml" || /^\/sitemap-\d+\.xml$/.test(path)) {
|
|
25
|
+
return new Response("Not found", { status: 404, headers: { "cache-control": "no-store", "x-robots-tag": NOINDEX } });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
7
28
|
const response = await next();
|
|
8
29
|
const env = await workerEnv();
|
|
9
30
|
const ancestors = frameAncestors(env?.TIDY_FRAME_ANCESTORS);
|
|
10
|
-
|
|
31
|
+
const apply = (headers: Headers) => {
|
|
32
|
+
if (ancestors.length > 0) applyFramePolicy(headers, ancestors);
|
|
33
|
+
if (!crawl) headers.set("x-robots-tag", NOINDEX);
|
|
34
|
+
};
|
|
11
35
|
// Response headers can be immutable (static assets, redirects); rebuild when so.
|
|
12
36
|
try {
|
|
13
|
-
|
|
37
|
+
apply(response.headers);
|
|
14
38
|
return response;
|
|
15
39
|
} catch {
|
|
16
40
|
const copy = new Response(response.body, response);
|
|
17
|
-
|
|
41
|
+
apply(copy.headers);
|
|
18
42
|
return copy;
|
|
19
43
|
}
|
|
20
44
|
};
|
package/src/version.ts
CHANGED