@matterandmotion/emdash-comics 0.0.0-stage → 0.1.0
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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matter & Motion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @matterandmotion/emdash-comics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Comic tools for [EmDash CMS](https://github.com/emdash-cms/emdash) sites: a bulk uploader, a comic page editor, reader components (stacked, vertical strips, paged, right to left), keyboard and swipe navigation, archives, chapters, cast, content warnings, a soft age gate, Portable Text blocks for embedding comics and characters, and searchable transcripts. Part of the [EmDash webcomic kit](https://github.com/matterandmotion/emdash-webcomic-kit).
|
|
4
|
+
|
|
5
|
+
> **Status: pre-release (0.x).** Components and props may change between minor versions.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pnpm add @matterandmotion/emdash-comics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
// astro.config.mjs
|
|
13
|
+
import comics from "@matterandmotion/emdash-comics";
|
|
14
|
+
|
|
15
|
+
emdash({ database, storage, plugins: [comics()] });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It's a native plugin: it runs in-process and can't be sandboxed or installed from the EmDash registry.
|
|
19
|
+
|
|
20
|
+
## What the plugin does
|
|
21
|
+
|
|
22
|
+
- **Searchable transcripts.** When a comic's `pages` are saved, it copies each page's transcript into the `transcript_text` field, so search indexes readable text instead of repeater JSON.
|
|
23
|
+
- **Portable Text blocks** for posts and pages, in the editor's slash menu under "Comics":
|
|
24
|
+
- **Comic**: a comic's first page (or thumbnail), linked to the comic. Fields: comic slug, optional caption.
|
|
25
|
+
- **Character card**: a cast member's portrait, name and introduction. Field: cast member slug.
|
|
26
|
+
|
|
27
|
+
Options (`comics({ … })`): `collection` (default `comics`), `pagesField` (`pages`), `transcriptField` (`transcript_text`), `adminGroup` (the sidebar folder for the bulk upload page, default `Comics`). The block renderers read the `comics` and `cast` collections and link comics as `/<series>/<slug>`.
|
|
28
|
+
|
|
29
|
+
## Bulk upload
|
|
30
|
+
|
|
31
|
+
An admin page (sidebar: **Comics → Bulk upload**) that turns many images into many comics:
|
|
32
|
+
|
|
33
|
+
1. **Images.** Pick images or a folder, or drop them. Each image becomes a comic; or images that differ only by a trailing page number become one comic (`ep01-1.png` and `ep01-2.png` make "ep01"); or each folder becomes one comic. Images taller than 4000 px are split into segments when they're uploaded.
|
|
34
|
+
2. **Details.** The series and chapter, titles from file names (`012-the-keeper` becomes "The keeper") or the series title and number, and the first number (by default, one after the series' highest).
|
|
35
|
+
3. **Publishing.** Save as drafts, publish now, or release on a schedule: a first date and time in the site's timezone, then every few days or on set weekdays. Dates in the past are published with that date (backdated, which needs permission to publish any content); future ones are scheduled.
|
|
36
|
+
4. **Review.** A table of every comic before anything is created, with editable titles and slugs. Comics that exist already are skipped, so running the same upload again after a failure only adds what's missing. They're recognised by their images first (see fingerprints below), whatever their titles, then by slug. Some images already in a comic, slugs used twice, and slugs held by a comic in the trash are flagged. To create a comic from images that are already in another, type a slug for it.
|
|
37
|
+
|
|
38
|
+
**Fingerprints.** Every page added by the bulk uploader or the pages widget keeps a fingerprint of the file it came from (`sourceHash`: the SHA-1 of the file, in EmDash's media hash format, `sha1:<hex>`). The segments of a split strip all keep the original file's. Comics from before this, or created another way, have none, so only their slugs are checked.
|
|
39
|
+
|
|
40
|
+
**Recent uploads.** Each upload is recorded in the plugin's storage, with who ran it, for 30 days, so it can be undone from any browser by anyone who can create content. Undo moves a batch's comics to the trash, where they can be restored. Deleting them for good from there frees their slugs for a fresh upload. Whether a batch's comics are still there is read from the content, so restoring or deleting one by hand shows up here too. Uploaded images stay in the media library, even those of a comic that failed to save: EmDash gives back the existing media item when the same file is uploaded again, so an image may belong to another comic, and a retry reuses it.
|
|
41
|
+
|
|
42
|
+
The page finds its collection from the schema: any collection whose pages field uses the `mm-comics:comic-pages` widget. Series and chapter fields are found by their pickers (or the names `series` and `chapter`), the number field by the name `number`, and their collections from the pickers' `collection` options. Put the comic collections in a sidebar folder named `Comics` (collection `group`) and the page joins them.
|
|
43
|
+
|
|
44
|
+
## Admin widgets
|
|
45
|
+
|
|
46
|
+
Field editors for the comic form. A schema field opts in with `widget` (in the seed or through the schema API):
|
|
47
|
+
|
|
48
|
+
| Widget | For | Does |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `mm-comics:comic-pages` | the `pages` repeater | Add many pages at once (pick or drop files, added in name order); images taller than 4000 px are split into equal segments in the browser before upload; reorder, remove, and edit each page's alt text, hover text and transcript. Each new page keeps its file's fingerprint (`sourceHash`). Uses the admin's own uploader, so it works with local storage and R2. |
|
|
51
|
+
| `mm-comics:series` | a series slug field | A dropdown of the series collection's entries (option `collection`, default `series`). |
|
|
52
|
+
| `mm-comics:chapter` | a chapter slug field | A dropdown of chapters labelled with their series (options `collection`, default `chapters`, and `seriesCollection`, default `series`). |
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{ "slug": "pages", "type": "repeater", "widget": "mm-comics:comic-pages", "validation": { "subFields": [...] } }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The site's build bundles the widgets with the admin's React and Kumo, so the package lists `react`, `@cloudflare/kumo` and `@emdash-cms/admin` as peer dependencies (EmDash sites already have them).
|
|
59
|
+
|
|
60
|
+
## Components
|
|
61
|
+
|
|
62
|
+
Import them by path:
|
|
63
|
+
|
|
64
|
+
```astro
|
|
65
|
+
---
|
|
66
|
+
import ComicReader from "@matterandmotion/emdash-comics/astro/ComicReader.astro";
|
|
67
|
+
import ComicNav from "@matterandmotion/emdash-comics/astro/ComicNav.astro";
|
|
68
|
+
import Transcript from "@matterandmotion/emdash-comics/astro/Transcript.astro";
|
|
69
|
+
---
|
|
70
|
+
<ComicReader title={comic.title} pages={comic.pages} direction={series.reading_direction} nextHref={next} />
|
|
71
|
+
<ComicNav first={first} previous={previous} next={next} latest={latest} direction={series.reading_direction} />
|
|
72
|
+
<Transcript pages={comic.pages} />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Component | Does |
|
|
76
|
+
|---|---|
|
|
77
|
+
| `ComicReader` | Renders the pages. `layout`: `stack` (default), `vertical` (edge to edge, the default for `direction="vertical"`), or `paged` (one page at a time; click or arrow keys turn pages). `direction="rtl"` flips page order and buttons for manga. Clicking the last page goes to `nextHref`, which is also prefetched. |
|
|
78
|
+
| `ComicNav` | First, previous, random, next and latest links. Arrow keys and horizontal swipes on the reader move through the series, flipped for right-to-left comics. |
|
|
79
|
+
| `Transcript` | Page-by-page transcript in a collapsible section. |
|
|
80
|
+
| `ArchiveGrid` | Thumbnail grid (`items: { href, title, number?, image? }[]`). |
|
|
81
|
+
| `ChapterList` | Chapters with their comics. |
|
|
82
|
+
| `CastGrid` | Cast members with portraits and introductions. |
|
|
83
|
+
| `ContentWarnings` | A warning note, or with `gate` a click-to-show wrapper around the comic (works without JavaScript). |
|
|
84
|
+
| `AgeGate` | A soft, client-side age confirmation remembered in the browser. A courtesy, not access control. |
|
|
85
|
+
|
|
86
|
+
### Animated pages
|
|
87
|
+
|
|
88
|
+
Cloudflare's image transforms turn animated GIFs into a single frame. The reader, archive grid and comic block detect GIF pages (by MIME type, then filename) and serve the original file without transforms, so they keep moving. `isAnimatedImage()` and `originalMediaUrl()` from `@matterandmotion/emdash-comics/astro` do the same for your own components.
|
|
89
|
+
|
|
90
|
+
### Old links
|
|
91
|
+
|
|
92
|
+
`legacyRedirects(map)` from `@matterandmotion/emdash-comics/astro` finds the new path for an old query-string address, such as WordPress's `/?p=123` or `/?comic=the-slug`, which EmDash's redirects can't match. `map` is the `{ "?p=123": "/series/slug" }` object that `emdash-webcomic import` writes. Extra parameters and encoding differences don't stop a match, and entries that point off the site are ignored. The webcomic template's `src/middleware.ts` shows the use.
|
|
93
|
+
|
|
94
|
+
### Long strips
|
|
95
|
+
|
|
96
|
+
EmDash doesn't transform images taller than 4000 px, so store long vertical strips as segments of at most 4000 px, one per page, and use the `vertical` layout to show them edge to edge.
|
|
97
|
+
|
|
98
|
+
## Content model
|
|
99
|
+
|
|
100
|
+
The comics collection needs a `pages` repeater with `image`, `alt`, `transcript` and `hovertext`, and a text `transcript_text` field. The webcomic template's seed has the full model.
|
|
101
|
+
|
|
102
|
+
The model is also available as data, for setup tools and templates (plain JavaScript, no build step):
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { comicProfile, comicTaxonomies } from "@matterandmotion/emdash-comics/profile";
|
|
106
|
+
|
|
107
|
+
comicProfile(); // comics, series, chapters and cast: collection and field definitions
|
|
108
|
+
comicTaxonomies(); // characters, locations, comic_tags and content_warnings
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The definitions match the body of EmDash's schema REST API. Numbering fields come from the serial profile in `@matterandmotion/emdash-series/profile`; merge the two with `mergeDefinitions` from `@matterandmotion/emdash-plugin-toolkit`, this profile first so its editor widgets are kept. [`emdash-webcomic migrate`](../webcomic-cli/README.md) does this for you.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT © Matter & Motion
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bulk upload history, kept in the plugin's storage so a recent batch can be
|
|
3
|
+
* undone from any browser, by anyone who can create comics. A batch records
|
|
4
|
+
* which comics an upload created and who ran it. Whether those comics are
|
|
5
|
+
* still there or in the trash is read from the content itself, so the history
|
|
6
|
+
* can't go out of date when someone restores or deletes one by hand.
|
|
7
|
+
*/
|
|
8
|
+
/** How long a batch can be undone from the bulk upload page. */
|
|
9
|
+
export declare const BATCH_RETENTION_DAYS = 30;
|
|
10
|
+
/** How many recent batches the page lists. */
|
|
11
|
+
export declare const BATCH_LIST_LIMIT = 20;
|
|
12
|
+
/** More comics than any one upload should create. */
|
|
13
|
+
export declare const MAX_BATCH_ENTRIES = 2000;
|
|
14
|
+
export interface BatchEntry {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
}
|
|
18
|
+
/** A stored batch. The storage ID is the batch ID, which the browser picks. */
|
|
19
|
+
export interface BatchRecord {
|
|
20
|
+
collection: string;
|
|
21
|
+
/** Series slug, when there is one. */
|
|
22
|
+
series?: string;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
/** Who ran the upload: their user ID, and their name when they have one. */
|
|
25
|
+
by: {
|
|
26
|
+
id: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
};
|
|
29
|
+
entries: BatchEntry[];
|
|
30
|
+
}
|
|
31
|
+
export interface Batch extends BatchRecord {
|
|
32
|
+
id: string;
|
|
33
|
+
}
|
|
34
|
+
export interface BatchInput {
|
|
35
|
+
id: string;
|
|
36
|
+
collection: string;
|
|
37
|
+
series?: string;
|
|
38
|
+
entries: BatchEntry[];
|
|
39
|
+
}
|
|
40
|
+
/** The storage calls this module makes (EmDash's `StorageCollection`). */
|
|
41
|
+
export interface BatchStore {
|
|
42
|
+
get(id: string): Promise<unknown>;
|
|
43
|
+
put(id: string, data: BatchRecord): Promise<void>;
|
|
44
|
+
query(options: {
|
|
45
|
+
where?: Record<string, string | {
|
|
46
|
+
gte?: string;
|
|
47
|
+
lt?: string;
|
|
48
|
+
}>;
|
|
49
|
+
orderBy?: Record<string, "asc" | "desc">;
|
|
50
|
+
limit?: number;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
items: Array<{
|
|
53
|
+
id: string;
|
|
54
|
+
data: unknown;
|
|
55
|
+
}>;
|
|
56
|
+
}>;
|
|
57
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
58
|
+
}
|
|
59
|
+
/** Storage indexes the queries below need. */
|
|
60
|
+
export declare const BATCH_INDEXES: (string | string[])[];
|
|
61
|
+
/** Checks a save request's body. Returns the batch, or why it's not acceptable. */
|
|
62
|
+
export declare function parseBatchInput(input: unknown): BatchInput | {
|
|
63
|
+
error: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Records a batch, or updates it as more comics are created. Only the person
|
|
67
|
+
* who started a batch can change it. Batches past the retention period are
|
|
68
|
+
* removed on the way.
|
|
69
|
+
*/
|
|
70
|
+
export declare function saveBatch(store: BatchStore, input: BatchInput, user: {
|
|
71
|
+
id: string;
|
|
72
|
+
name?: string | null;
|
|
73
|
+
}, now?: Date): Promise<{
|
|
74
|
+
ok: true;
|
|
75
|
+
batch: Batch;
|
|
76
|
+
} | {
|
|
77
|
+
ok: false;
|
|
78
|
+
forbidden: true;
|
|
79
|
+
}>;
|
|
80
|
+
/** A collection's recent batches, newest first. */
|
|
81
|
+
export declare function listBatches(store: BatchStore, collection: string, now?: Date): Promise<Batch[]>;
|
|
82
|
+
/** Deletes batches past the retention period, a hundred at a time. */
|
|
83
|
+
export declare function pruneBatches(store: BatchStore, now?: Date): Promise<number>;
|
|
84
|
+
//# sourceMappingURL=batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../src/batches.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACd;AAED,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,OAAO,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,KA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AE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC1C,GAAG,OAAa,GACd,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC,CActE;AAED,mDAAmD;AACnD,wBAAsB,WAAW,CAChC,KAAK,EAAE,UAAU,EACjB,UAAU,EAAE,MAAM,EAClB,GAAG,OAAa,GACd,OAAO,CAAC,KAAK,EAAE,CAAC,CAOlB;AAED,sEAAsE;AACtE,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAIvF"}
|
package/dist/batches.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bulk upload history, kept in the plugin's storage so a recent batch can be
|
|
3
|
+
* undone from any browser, by anyone who can create comics. A batch records
|
|
4
|
+
* which comics an upload created and who ran it. Whether those comics are
|
|
5
|
+
* still there or in the trash is read from the content itself, so the history
|
|
6
|
+
* can't go out of date when someone restores or deletes one by hand.
|
|
7
|
+
*/
|
|
8
|
+
/** How long a batch can be undone from the bulk upload page. */
|
|
9
|
+
export const BATCH_RETENTION_DAYS = 30;
|
|
10
|
+
/** How many recent batches the page lists. */
|
|
11
|
+
export const BATCH_LIST_LIMIT = 20;
|
|
12
|
+
/** More comics than any one upload should create. */
|
|
13
|
+
export const MAX_BATCH_ENTRIES = 2000;
|
|
14
|
+
/** Storage indexes the queries below need. */
|
|
15
|
+
export const BATCH_INDEXES = ["createdAt", ["collection", "createdAt"]];
|
|
16
|
+
const BATCH_ID = /^[A-Za-z0-9-]{8,64}$/;
|
|
17
|
+
const SLUG = /^[A-Za-z0-9_-]{1,100}$/;
|
|
18
|
+
function text(value, max) {
|
|
19
|
+
return typeof value === "string" ? value.slice(0, max) : undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Checks a save request's body. Returns the batch, or why it's not acceptable. */
|
|
22
|
+
export function parseBatchInput(input) {
|
|
23
|
+
if (!input || typeof input !== "object")
|
|
24
|
+
return { error: "Expected a JSON object" };
|
|
25
|
+
const body = input;
|
|
26
|
+
if (typeof body.id !== "string" || !BATCH_ID.test(body.id))
|
|
27
|
+
return { error: "Invalid batch id" };
|
|
28
|
+
if (typeof body.collection !== "string" || !SLUG.test(body.collection)) {
|
|
29
|
+
return { error: "Invalid collection" };
|
|
30
|
+
}
|
|
31
|
+
if (body.series !== undefined && (typeof body.series !== "string" || !SLUG.test(body.series))) {
|
|
32
|
+
return { error: "Invalid series" };
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(body.entries) || body.entries.length > MAX_BATCH_ENTRIES) {
|
|
35
|
+
return { error: `Expected up to ${MAX_BATCH_ENTRIES} entries` };
|
|
36
|
+
}
|
|
37
|
+
const entries = [];
|
|
38
|
+
for (const item of body.entries) {
|
|
39
|
+
const entry = item;
|
|
40
|
+
const id = text(entry?.id, 100);
|
|
41
|
+
if (!id)
|
|
42
|
+
return { error: "Each entry needs an id" };
|
|
43
|
+
entries.push({ id, title: text(entry?.title, 300) ?? "" });
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
id: body.id,
|
|
47
|
+
collection: body.collection,
|
|
48
|
+
...(typeof body.series === "string" ? { series: body.series } : {}),
|
|
49
|
+
entries,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function isRecord(value) {
|
|
53
|
+
if (!value || typeof value !== "object")
|
|
54
|
+
return false;
|
|
55
|
+
const record = value;
|
|
56
|
+
return (typeof record.collection === "string" &&
|
|
57
|
+
typeof record.createdAt === "string" &&
|
|
58
|
+
typeof record.by?.id === "string" &&
|
|
59
|
+
Array.isArray(record.entries));
|
|
60
|
+
}
|
|
61
|
+
function cutoff(now) {
|
|
62
|
+
return new Date(now.getTime() - BATCH_RETENTION_DAYS * 86_400_000).toISOString();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Records a batch, or updates it as more comics are created. Only the person
|
|
66
|
+
* who started a batch can change it. Batches past the retention period are
|
|
67
|
+
* removed on the way.
|
|
68
|
+
*/
|
|
69
|
+
export async function saveBatch(store, input, user, now = new Date()) {
|
|
70
|
+
const stored = await store.get(input.id);
|
|
71
|
+
const previous = isRecord(stored) ? stored : null;
|
|
72
|
+
if (previous && previous.by.id !== user.id)
|
|
73
|
+
return { ok: false, forbidden: true };
|
|
74
|
+
const record = {
|
|
75
|
+
collection: input.collection,
|
|
76
|
+
...(input.series ? { series: input.series } : {}),
|
|
77
|
+
createdAt: previous?.createdAt ?? now.toISOString(),
|
|
78
|
+
by: previous?.by ?? { id: user.id, ...(user.name ? { name: user.name } : {}) },
|
|
79
|
+
entries: input.entries,
|
|
80
|
+
};
|
|
81
|
+
await store.put(input.id, record);
|
|
82
|
+
await pruneBatches(store, now);
|
|
83
|
+
return { ok: true, batch: { id: input.id, ...record } };
|
|
84
|
+
}
|
|
85
|
+
/** A collection's recent batches, newest first. */
|
|
86
|
+
export async function listBatches(store, collection, now = new Date()) {
|
|
87
|
+
const result = await store.query({
|
|
88
|
+
where: { collection, createdAt: { gte: cutoff(now) } },
|
|
89
|
+
orderBy: { createdAt: "desc" },
|
|
90
|
+
limit: BATCH_LIST_LIMIT,
|
|
91
|
+
});
|
|
92
|
+
return result.items.flatMap(({ id, data }) => (isRecord(data) ? [{ id, ...data }] : []));
|
|
93
|
+
}
|
|
94
|
+
/** Deletes batches past the retention period, a hundred at a time. */
|
|
95
|
+
export async function pruneBatches(store, now = new Date()) {
|
|
96
|
+
const old = await store.query({ where: { createdAt: { lt: cutoff(now) } }, limit: 100 });
|
|
97
|
+
if (old.items.length === 0)
|
|
98
|
+
return 0;
|
|
99
|
+
return store.deleteMany(old.items.map((item) => item.id));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=batches.js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AAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACzF,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text blocks for posts and pages: embed a comic, or show a cast
|
|
3
|
+
* member's card. Editors pick them from the slash menu and fill in a slug;
|
|
4
|
+
* the renderers (`./blocks`) look the entry up when the page renders.
|
|
5
|
+
*/
|
|
6
|
+
export declare const COMIC_EMBED_BLOCK = "comic-embed";
|
|
7
|
+
export declare const CHARACTER_CARD_BLOCK = "character-card";
|
|
8
|
+
export declare const portableTextBlocks: {
|
|
9
|
+
type: string;
|
|
10
|
+
label: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
description: string;
|
|
13
|
+
category: string;
|
|
14
|
+
fields: ({
|
|
15
|
+
type: "text_input";
|
|
16
|
+
action_id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
placeholder: string;
|
|
19
|
+
} | {
|
|
20
|
+
placeholder?: never;
|
|
21
|
+
type: "text_input";
|
|
22
|
+
action_id: string;
|
|
23
|
+
label: string;
|
|
24
|
+
})[];
|
|
25
|
+
}[];
|
|
26
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD,eAAO,MAAM,kBAAkB;;;;;;;cASrB,YAAY;;;;;;cAMZ,YAAY;;;;GAqBrB,CAAC"}
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text blocks for posts and pages: embed a comic, or show a cast
|
|
3
|
+
* member's card. Editors pick them from the slash menu and fill in a slug;
|
|
4
|
+
* the renderers (`./blocks`) look the entry up when the page renders.
|
|
5
|
+
*/
|
|
6
|
+
export const COMIC_EMBED_BLOCK = "comic-embed";
|
|
7
|
+
export const CHARACTER_CARD_BLOCK = "character-card";
|
|
8
|
+
export const portableTextBlocks = [
|
|
9
|
+
{
|
|
10
|
+
type: COMIC_EMBED_BLOCK,
|
|
11
|
+
label: "Comic",
|
|
12
|
+
icon: "image",
|
|
13
|
+
description: "Show a comic's first page, linked to the comic.",
|
|
14
|
+
category: "Comics",
|
|
15
|
+
fields: [
|
|
16
|
+
{
|
|
17
|
+
type: "text_input",
|
|
18
|
+
action_id: "comic",
|
|
19
|
+
label: "Comic slug",
|
|
20
|
+
placeholder: "the-first-page",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "text_input",
|
|
24
|
+
action_id: "caption",
|
|
25
|
+
label: "Caption (optional)",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: CHARACTER_CARD_BLOCK,
|
|
31
|
+
label: "Character card",
|
|
32
|
+
icon: "user",
|
|
33
|
+
description: "Show a cast member's portrait and introduction.",
|
|
34
|
+
category: "Comics",
|
|
35
|
+
fields: [
|
|
36
|
+
{
|
|
37
|
+
type: "text_input",
|
|
38
|
+
action_id: "character",
|
|
39
|
+
label: "Cast member slug",
|
|
40
|
+
placeholder: "captain-ada",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
//# sourceMappingURL=blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC;QACC,IAAI,EAAE,iBAAiB;QACvB,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,iDAAiD;QAC9D,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE;YACP;gBACC,IAAI,EAAE,YAAqB;gBAC3B,SAAS,EAAE,OAAO;gBAClB,KAAK,EAAE,YAAY;gBACnB,WAAW,EAAE,gBAAgB;aAC7B;YACD;gBACC,IAAI,EAAE,YAAqB;gBAC3B,SAAS,EAAE,SAAS;gBACpB,KAAK,EAAE,oBAAoB;aAC3B;SACD;KACD;IACD;QACC,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,gBAAgB;QACvB,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,iDAAiD;QAC9D,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE;YACP;gBACC,IAAI,EAAE,YAAqB;gBAC3B,SAAS,EAAE,WAAW;gBACtB,KAAK,EAAE,kBAAkB;gBACzB,WAAW,EAAE,aAAa;aAC1B;SACD;KACD;CACD,CAAC"}
|
package/dist/id.d.ts
ADDED
package/dist/id.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,eAAO,MAAM,SAAS,cAAc,CAAC"}
|
package/dist/id.js
ADDED
package/dist/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type PluginDescriptor } from "emdash";
|
|
2
|
+
export { BATCH_RETENTION_DAYS, type Batch, type BatchEntry } from "./batches.js";
|
|
3
|
+
export { CHARACTER_CARD_BLOCK, COMIC_EMBED_BLOCK } from "./blocks.js";
|
|
4
|
+
export { PLUGIN_ID } from "./id.js";
|
|
5
|
+
export { isAnimatedImage, type MediaLike, originalMediaUrl } from "./media.js";
|
|
6
|
+
export { MAX_TRANSCRIPT_LENGTH, transcriptText } from "./transcripts.js";
|
|
7
|
+
/** Kept in step with package.json (a test checks it). */
|
|
8
|
+
export declare const VERSION = "0.0.0";
|
|
9
|
+
export interface ComicsOptions {
|
|
10
|
+
/** The comics collection. Default "comics". */
|
|
11
|
+
collection?: string;
|
|
12
|
+
/** The repeater holding the comic's pages. Default "pages". */
|
|
13
|
+
pagesField?: string;
|
|
14
|
+
/** The searchable text field transcripts are copied into. Default "transcript_text". */
|
|
15
|
+
transcriptField?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The admin sidebar folder for the bulk upload page. It joins collections
|
|
18
|
+
* with the same `group`. Default "Comics".
|
|
19
|
+
*/
|
|
20
|
+
adminGroup?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ResolvedOptions {
|
|
23
|
+
collection: string;
|
|
24
|
+
pagesField: string;
|
|
25
|
+
transcriptField: string;
|
|
26
|
+
}
|
|
27
|
+
/** The plugin's admin pages; the admin entry exports a component for each path. */
|
|
28
|
+
export declare function adminPages(options?: Pick<ComicsOptions, "adminGroup">): {
|
|
29
|
+
path: string;
|
|
30
|
+
label: string;
|
|
31
|
+
icon: string;
|
|
32
|
+
group: string;
|
|
33
|
+
}[];
|
|
34
|
+
/**
|
|
35
|
+
* Register in `astro.config.mjs`: `emdash({ plugins: [comics()] })`. It's a
|
|
36
|
+
* native plugin, so it runs in-process and can't be sandboxed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function comics(options?: ComicsOptions): PluginDescriptor<ComicsOptions>;
|
|
39
|
+
/** Copies page transcripts into the transcript field when a comic's pages are saved. */
|
|
40
|
+
export declare function withTranscript(content: Record<string, unknown>, options: Pick<ResolvedOptions, "pagesField" | "transcriptField">): Record<string, unknown> | undefined;
|
|
41
|
+
/** Called by EmDash's native plugin loader. */
|
|
42
|
+
export declare function createPlugin(options?: ComicsOptions): import("emdash").ResolvedPlugin<{
|
|
43
|
+
batches: {
|
|
44
|
+
indexes: (string | string[])[];
|
|
45
|
+
};
|
|
46
|
+
}>;
|
|
47
|
+
export default comics;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAuC,MAAM,QAAQ,CAAC;AAYlG,OAAO,EAAE,oBAAoB,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzE,yDAAyD;AACzD,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,MAAM,WAAW,aAAa;IAC7B,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACxB;AAUD,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,YAAY,CAAM;;;;;IASzE;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAcnF;AAED,wFAAwF;AACxF,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,GAAG,iBAAiB,CAAC,GAC9D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAMrC;AAQD,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB;;QAQ1C,OAAO;;GAyCpB;eAEc,MAAM"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { definePlugin, PluginRouteError } from "emdash";
|
|
2
|
+
import { BATCH_INDEXES, listBatches, parseBatchInput, saveBatch, } from "./batches.js";
|
|
3
|
+
import { portableTextBlocks } from "./blocks.js";
|
|
4
|
+
import { PLUGIN_ID } from "./id.js";
|
|
5
|
+
import { transcriptText } from "./transcripts.js";
|
|
6
|
+
export { BATCH_RETENTION_DAYS } from "./batches.js";
|
|
7
|
+
export { CHARACTER_CARD_BLOCK, COMIC_EMBED_BLOCK } from "./blocks.js";
|
|
8
|
+
export { PLUGIN_ID } from "./id.js";
|
|
9
|
+
export { isAnimatedImage, originalMediaUrl } from "./media.js";
|
|
10
|
+
export { MAX_TRANSCRIPT_LENGTH, transcriptText } from "./transcripts.js";
|
|
11
|
+
/** Kept in step with package.json (a test checks it). */
|
|
12
|
+
export const VERSION = "0.0.0";
|
|
13
|
+
const PACKAGE = "@matterandmotion/emdash-comics";
|
|
14
|
+
function resolve(options) {
|
|
15
|
+
return {
|
|
16
|
+
collection: options.collection ?? "comics",
|
|
17
|
+
pagesField: options.pagesField ?? "pages",
|
|
18
|
+
transcriptField: options.transcriptField ?? "transcript_text",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The plugin's admin pages; the admin entry exports a component for each path. */
|
|
22
|
+
export function adminPages(options = {}) {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
path: "/bulk-upload",
|
|
26
|
+
label: "Bulk upload",
|
|
27
|
+
icon: "upload",
|
|
28
|
+
group: options.adminGroup ?? "Comics",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Register in `astro.config.mjs`: `emdash({ plugins: [comics()] })`. It's a
|
|
34
|
+
* native plugin, so it runs in-process and can't be sandboxed.
|
|
35
|
+
*/
|
|
36
|
+
export function comics(options = {}) {
|
|
37
|
+
return {
|
|
38
|
+
id: PLUGIN_ID,
|
|
39
|
+
version: VERSION,
|
|
40
|
+
displayName: "Comics",
|
|
41
|
+
description: "Comic page editor, bulk upload, comic blocks, searchable transcripts and reader components.",
|
|
42
|
+
format: "native",
|
|
43
|
+
entrypoint: PACKAGE,
|
|
44
|
+
adminEntry: `${PACKAGE}/admin`,
|
|
45
|
+
componentsEntry: `${PACKAGE}/blocks`,
|
|
46
|
+
adminPages: adminPages(options),
|
|
47
|
+
options,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Copies page transcripts into the transcript field when a comic's pages are saved. */
|
|
51
|
+
export function withTranscript(content, options) {
|
|
52
|
+
// Partial updates that don't touch the pages leave the transcript alone.
|
|
53
|
+
if (!(options.pagesField in content))
|
|
54
|
+
return undefined;
|
|
55
|
+
const text = transcriptText(content[options.pagesField]);
|
|
56
|
+
if (content[options.transcriptField] === text)
|
|
57
|
+
return undefined;
|
|
58
|
+
return { ...content, [options.transcriptField]: text };
|
|
59
|
+
}
|
|
60
|
+
function batchStore(ctx) {
|
|
61
|
+
const store = ctx.storage.batches;
|
|
62
|
+
if (!store)
|
|
63
|
+
throw PluginRouteError.internal("The batches storage collection is missing");
|
|
64
|
+
return store;
|
|
65
|
+
}
|
|
66
|
+
/** Called by EmDash's native plugin loader. */
|
|
67
|
+
export function createPlugin(options = {}) {
|
|
68
|
+
const settings = resolve(options);
|
|
69
|
+
return definePlugin({
|
|
70
|
+
id: PLUGIN_ID,
|
|
71
|
+
version: VERSION,
|
|
72
|
+
capabilities: ["content:write"],
|
|
73
|
+
storage: {
|
|
74
|
+
// Bulk upload history (see batches.ts).
|
|
75
|
+
batches: { indexes: BATCH_INDEXES },
|
|
76
|
+
},
|
|
77
|
+
routes: {
|
|
78
|
+
/** Recent bulk uploads into a collection: GET ?collection=comics */
|
|
79
|
+
batches: {
|
|
80
|
+
permission: "content:create",
|
|
81
|
+
methods: ["GET"],
|
|
82
|
+
handler: async (ctx) => {
|
|
83
|
+
const input = (ctx.input ?? {});
|
|
84
|
+
const collection = typeof input.collection === "string" ? input.collection : "";
|
|
85
|
+
if (!collection)
|
|
86
|
+
throw PluginRouteError.badRequest("collection is required");
|
|
87
|
+
return { batches: await listBatches(batchStore(ctx), collection) };
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
/** Records a bulk upload, or adds the comics it has created since. */
|
|
91
|
+
"save-batch": {
|
|
92
|
+
permission: "content:create",
|
|
93
|
+
methods: ["POST"],
|
|
94
|
+
handler: async (ctx) => {
|
|
95
|
+
if (!ctx.user)
|
|
96
|
+
throw PluginRouteError.unauthorized();
|
|
97
|
+
const input = parseBatchInput(ctx.input);
|
|
98
|
+
if ("error" in input)
|
|
99
|
+
throw PluginRouteError.badRequest(input.error);
|
|
100
|
+
const result = await saveBatch(batchStore(ctx), input, ctx.user);
|
|
101
|
+
if (!result.ok)
|
|
102
|
+
throw PluginRouteError.forbidden("This upload was started by someone else");
|
|
103
|
+
return { batch: result.batch };
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
hooks: {
|
|
108
|
+
"content:beforeSave": {
|
|
109
|
+
priority: 60,
|
|
110
|
+
timeout: 2000,
|
|
111
|
+
handler: async (event) => {
|
|
112
|
+
if (event.collection !== settings.collection)
|
|
113
|
+
return;
|
|
114
|
+
return withTranscript(event.content, settings);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
admin: { entry: `${PACKAGE}/admin`, portableTextBlocks, pages: adminPages(options) },
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export default comics;
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,gBAAgB,EAAqB,MAAM,QAAQ,CAAC;AAClG,OAAO,EACN,aAAa,EAEb,WAAW,EACX,eAAe,EACf,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAA+B,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,eAAe,EAAkB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzE,yDAAyD;AACzD,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAC/B,MAAM,OAAO,GAAG,gCAAgC,CAAC;AAsBjD,SAAS,OAA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AAG,EAAE,EAAE;oBACtB,IAAI,CAAC,GAAG,CAAC,IAAI;wBAAE,MAAM,gBAAgB,CAAC,YAAY,EAAE,CAAC;oBACrD,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACzC,IAAI,OAAO,IAAI,KAAK;wBAAE,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrE,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;oBACjE,IAAI,CAAC,MAAM,CAAC,EAAE;wBACb,MAAM,gBAAgB,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;oBAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,CAAC;aACD;SACD;QACD,KAAK,EAAE;YACN,oBAAoB,EAAE;gBACrB,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACxB,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC,UAAU;wBAAE,OAAO;oBACrD,OAAO,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAChD,CAAC;aACD;SACD;QACD,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,QAAQ,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE;KACpF,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* Builds a lookup from an address map. The lookup returns the new path for a
|
|
9
|
+
* request to an old address, or null. Each `key=value` pair in the query is
|
|
10
|
+
* tried on its own, so extra parameters (`&utm_source=…`) don't stop a match,
|
|
11
|
+
* and percent-encoding differences don't either. Entries that don't point at
|
|
12
|
+
* a path on this site are ignored.
|
|
13
|
+
*/
|
|
14
|
+
export declare function legacyRedirects(map: Readonly<Record<string, unknown>>): (url: URL) => string | null;
|
|
15
|
+
//# sourceMappingURL=legacy-redirects.d.ts.map
|