@matterandmotion/emdash-comics 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/batches.d.ts +84 -0
- package/dist/batches.d.ts.map +1 -0
- package/dist/batches.js +101 -0
- package/dist/batches.js.map +1 -0
- package/dist/blocks.d.ts +26 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +45 -0
- package/dist/blocks.js.map +1 -0
- package/dist/id.d.ts +3 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +3 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-redirects.d.ts +15 -0
- package/dist/legacy-redirects.d.ts.map +1 -0
- package/dist/legacy-redirects.js +58 -0
- package/dist/legacy-redirects.js.map +1 -0
- package/dist/media.d.ts +26 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +48 -0
- package/dist/media.js.map +1 -0
- package/dist/transcripts.d.ts +10 -0
- package/dist/transcripts.d.ts.map +1 -0
- package/dist/transcripts.js +22 -0
- package/dist/transcripts.js.map +1 -0
- package/package.json +67 -3
- package/profile/index.d.mts +46 -0
- package/profile/index.mjs +197 -0
- package/src/admin/BulkUploadPage.tsx +1004 -0
- package/src/admin/ComicPagesField.tsx +202 -0
- package/src/admin/bulk/api.ts +215 -0
- package/src/admin/bulk/config.ts +87 -0
- package/src/admin/bulk/files.ts +76 -0
- package/src/admin/bulk/history.ts +45 -0
- package/src/admin/bulk/plan.ts +446 -0
- package/src/admin/fingerprint.ts +26 -0
- package/src/admin/index.tsx +19 -0
- package/src/admin/media.ts +75 -0
- package/src/admin/pickers.tsx +132 -0
- package/src/admin/segments.ts +36 -0
- package/src/admin/slice.ts +46 -0
- package/src/admin/types.ts +47 -0
- package/src/astro/AgeGate.astro +85 -0
- package/src/astro/ArchiveGrid.astro +79 -0
- package/src/astro/CastGrid.astro +63 -0
- package/src/astro/ChapterList.astro +57 -0
- package/src/astro/CharacterCard.astro +54 -0
- package/src/astro/ComicEmbed.astro +55 -0
- package/src/astro/ComicNav.astro +131 -0
- package/src/astro/ComicReader.astro +193 -0
- package/src/astro/ContentWarnings.astro +61 -0
- package/src/astro/Transcript.astro +43 -0
- package/src/astro/astro-modules.d.ts +6 -0
- package/src/astro/blocks.ts +11 -0
- package/src/astro/index.ts +20 -0
- package/src/batches.ts +154 -0
- package/src/blocks.ts +46 -0
- package/src/id.ts +2 -0
- package/src/index.ts +152 -0
- package/src/legacy-redirects.ts +59 -0
- package/src/media.ts +60 -0
- package/src/transcripts.ts +20 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Old query-string addresses, such as WordPress's `/?p=123` and
|
|
3
|
+
* `/?comic=the-slug`. EmDash's redirects match paths only, so
|
|
4
|
+
* `emdash-webcomic import` writes these into a map (`{ "?p=123": "/series/slug" }`)
|
|
5
|
+
* and the site's middleware looks requests up with `legacyRedirects()`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** WordPress serves query-string permalinks from its front page. */
|
|
9
|
+
const LEGACY_PATHS = new Set(["/", "/index.php"]);
|
|
10
|
+
|
|
11
|
+
/** `key=value` with both halves decoded, or null. `+` is a space, as in forms. */
|
|
12
|
+
function normalizePair(pair: string): string | null {
|
|
13
|
+
const equals = pair.indexOf("=");
|
|
14
|
+
if (equals <= 0) return null;
|
|
15
|
+
try {
|
|
16
|
+
const decode = (text: string) => decodeURIComponent(text.replaceAll("+", " "));
|
|
17
|
+
return `${decode(pair.slice(0, equals))}=${decode(pair.slice(equals + 1))}`;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A path on this site: no scheme, no host. */
|
|
24
|
+
function isSitePath(value: unknown): value is string {
|
|
25
|
+
return (
|
|
26
|
+
typeof value === "string" &&
|
|
27
|
+
value.startsWith("/") &&
|
|
28
|
+
!value.startsWith("//") &&
|
|
29
|
+
!value.startsWith("/\\")
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Builds a lookup from an address map. The lookup returns the new path for a
|
|
35
|
+
* request to an old address, or null. Each `key=value` pair in the query is
|
|
36
|
+
* tried on its own, so extra parameters (`&utm_source=…`) don't stop a match,
|
|
37
|
+
* and percent-encoding differences don't either. Entries that don't point at
|
|
38
|
+
* a path on this site are ignored.
|
|
39
|
+
*/
|
|
40
|
+
export function legacyRedirects(
|
|
41
|
+
map: Readonly<Record<string, unknown>>,
|
|
42
|
+
): (url: URL) => string | null {
|
|
43
|
+
const lookup = new Map<string, string>();
|
|
44
|
+
for (const [address, destination] of Object.entries(map)) {
|
|
45
|
+
if (!address.startsWith("?") || !isSitePath(destination)) continue;
|
|
46
|
+
const key = normalizePair(address.slice(1));
|
|
47
|
+
// Percent-encode the path the way a browser would, for the Location header.
|
|
48
|
+
if (key) lookup.set(key, new URL(destination, "https://site.invalid").pathname);
|
|
49
|
+
}
|
|
50
|
+
return (url) => {
|
|
51
|
+
if (lookup.size === 0 || !url.search || !LEGACY_PATHS.has(url.pathname)) return null;
|
|
52
|
+
for (const pair of url.search.slice(1).split("&")) {
|
|
53
|
+
const key = normalizePair(pair);
|
|
54
|
+
const destination = key === null ? undefined : lookup.get(key);
|
|
55
|
+
if (destination) return destination;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
}
|
package/src/media.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media helpers for comic pages. Cloudflare's image transforms flatten animated
|
|
3
|
+
* GIFs to a single frame (V3), so the reader serves GIF pages untouched, using
|
|
4
|
+
* the same original URL EmDash's own image component would build.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface MediaLike {
|
|
8
|
+
id?: string;
|
|
9
|
+
provider?: string;
|
|
10
|
+
src?: string;
|
|
11
|
+
filename?: string;
|
|
12
|
+
mimeType?: string;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
alt?: string;
|
|
16
|
+
meta?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const INTERNAL_MEDIA_PREFIX = "/_emdash/api/media/file/";
|
|
20
|
+
const SAFE_STORAGE_KEY = /^[A-Za-z0-9._-]+$/;
|
|
21
|
+
|
|
22
|
+
export function asMedia(value: unknown): MediaLike | null {
|
|
23
|
+
if (typeof value === "string") return value ? { src: value } : null;
|
|
24
|
+
if (typeof value !== "object" || value === null) return null;
|
|
25
|
+
return value as MediaLike;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** True for GIF images, judged by MIME type, then filename or URL. */
|
|
29
|
+
export function isAnimatedImage(value: unknown): boolean {
|
|
30
|
+
const media = asMedia(value);
|
|
31
|
+
if (!media) return false;
|
|
32
|
+
if (media.mimeType) return media.mimeType.toLowerCase() === "image/gif";
|
|
33
|
+
const name = media.filename ?? media.src ?? "";
|
|
34
|
+
return /\.gif(?:$|[?#])/i.test(name);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The original (untransformed) URL of a local media item. `resolve` is
|
|
39
|
+
* `Astro.locals.emdash?.getPublicMediaUrl`, which maps a storage key to its
|
|
40
|
+
* public URL (an R2 custom domain, for example).
|
|
41
|
+
*/
|
|
42
|
+
export function originalMediaUrl(
|
|
43
|
+
value: unknown,
|
|
44
|
+
resolve?: ((storageKey: string) => string) | undefined,
|
|
45
|
+
): string | null {
|
|
46
|
+
const media = asMedia(value);
|
|
47
|
+
if (!media) return null;
|
|
48
|
+
const storageKey = media.meta?.storageKey;
|
|
49
|
+
if (typeof storageKey === "string" && SAFE_STORAGE_KEY.test(storageKey)) {
|
|
50
|
+
return resolve ? resolve(storageKey) : `${INTERNAL_MEDIA_PREFIX}${storageKey}`;
|
|
51
|
+
}
|
|
52
|
+
if (media.src) {
|
|
53
|
+
if (resolve && media.src.startsWith(INTERNAL_MEDIA_PREFIX)) {
|
|
54
|
+
const key = media.src.slice(INTERNAL_MEDIA_PREFIX.length);
|
|
55
|
+
if (SAFE_STORAGE_KEY.test(key)) return resolve(key);
|
|
56
|
+
}
|
|
57
|
+
return media.src;
|
|
58
|
+
}
|
|
59
|
+
return media.id ? `${INTERNAL_MEDIA_PREFIX}${media.id}` : null;
|
|
60
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comic transcripts. Each page in the `pages` repeater can carry a transcript;
|
|
3
|
+
* the plugin copies them into one plain-text field so search can index and
|
|
4
|
+
* show them (raw repeater JSON makes poor search snippets).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** EmDash's text fields hold plenty, but a transcript this long is a mistake. */
|
|
8
|
+
export const MAX_TRANSCRIPT_LENGTH = 50_000;
|
|
9
|
+
|
|
10
|
+
/** Joins the pages' transcripts, in page order, separated by blank lines. */
|
|
11
|
+
export function transcriptText(pages: unknown): string {
|
|
12
|
+
if (!Array.isArray(pages)) return "";
|
|
13
|
+
const parts: string[] = [];
|
|
14
|
+
for (const page of pages) {
|
|
15
|
+
if (typeof page !== "object" || page === null) continue;
|
|
16
|
+
const transcript = (page as { transcript?: unknown }).transcript;
|
|
17
|
+
if (typeof transcript === "string" && transcript.trim()) parts.push(transcript.trim());
|
|
18
|
+
}
|
|
19
|
+
return parts.join("\n\n").slice(0, MAX_TRANSCRIPT_LENGTH);
|
|
20
|
+
}
|