@geekity/cms 0.35.0 → 0.37.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/admin/components/blocks.njk +250 -0
- package/admin/components/card.njk +4 -2
- package/admin/components/job-status.njk +15 -10
- package/admin/components/upload.njk +26 -0
- package/admin/pages/comments/all.njk +1 -1
- package/admin/pages/dashboard/home.njk +33 -32
- package/admin/pages/documents/editor.njk +34 -19
- package/admin/pages/federation/followers.njk +3 -2
- package/admin/pages/media/file.njk +5 -4
- package/admin/pages/media/library.njk +7 -3
- package/admin/pages/plugins/screen.njk +5 -35
- package/admin/pages/settings/general.njk +4 -1
- package/admin/pages/tools/export.njk +54 -51
- package/admin/pages/tools/maintenance.njk +2 -1
- package/admin/pages/users/edit.njk +3 -0
- package/admin/src/admin.css +1 -0
- package/admin/static/admin.css +374 -0
- package/admin/static/job-status.js +158 -0
- package/admin/static/upload-drop.js +225 -0
- package/dist/admin/blocks.d.ts +133 -0
- package/dist/admin/blocks.d.ts.map +1 -0
- package/dist/admin/blocks.js +454 -0
- package/dist/admin/blocks.js.map +1 -0
- package/dist/admin/core-widgets.d.ts +3 -0
- package/dist/admin/core-widgets.d.ts.map +1 -0
- package/dist/admin/core-widgets.js +17 -0
- package/dist/admin/core-widgets.js.map +1 -0
- package/dist/admin/documents.d.ts.map +1 -1
- package/dist/admin/documents.js +0 -2
- package/dist/admin/documents.js.map +1 -1
- package/dist/admin/engagement.d.ts +16 -0
- package/dist/admin/engagement.d.ts.map +1 -0
- package/dist/admin/engagement.js +38 -0
- package/dist/admin/engagement.js.map +1 -0
- package/dist/admin/federation.d.ts +2 -0
- package/dist/admin/federation.d.ts.map +1 -1
- package/dist/admin/federation.js +2 -1
- package/dist/admin/federation.js.map +1 -1
- package/dist/admin/formatting.d.ts +1 -0
- package/dist/admin/formatting.d.ts.map +1 -1
- package/dist/admin/formatting.js +18 -0
- package/dist/admin/formatting.js.map +1 -1
- package/dist/admin/index.d.ts +2 -2
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +2 -2
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/job-status.d.ts +1 -0
- package/dist/admin/job-status.d.ts.map +1 -1
- package/dist/admin/job-status.js +1 -0
- package/dist/admin/job-status.js.map +1 -1
- package/dist/admin/media.d.ts +6 -9
- package/dist/admin/media.d.ts.map +1 -1
- package/dist/admin/media.js +85 -27
- package/dist/admin/media.js.map +1 -1
- package/dist/admin/posts-by-path.d.ts +11 -0
- package/dist/admin/posts-by-path.d.ts.map +1 -0
- package/dist/admin/posts-by-path.js +59 -0
- package/dist/admin/posts-by-path.js.map +1 -0
- package/dist/admin/routes.d.ts +0 -2
- package/dist/admin/routes.d.ts.map +1 -1
- package/dist/admin/routes.js +24 -12
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/templates.d.ts.map +1 -1
- package/dist/admin/templates.js +2 -0
- package/dist/admin/templates.js.map +1 -1
- package/dist/admin/tools.js +1 -1
- package/dist/admin/tools.js.map +1 -1
- package/dist/admin/uploads.d.ts +2 -1
- package/dist/admin/uploads.d.ts.map +1 -1
- package/dist/admin/uploads.js +5 -2
- package/dist/admin/uploads.js.map +1 -1
- package/dist/admin/widget-fediverse.d.ts +3 -0
- package/dist/admin/widget-fediverse.d.ts.map +1 -0
- package/dist/admin/widget-fediverse.js +49 -0
- package/dist/admin/widget-fediverse.js.map +1 -0
- package/dist/admin/widget-followers.d.ts +3 -0
- package/dist/admin/widget-followers.d.ts.map +1 -0
- package/dist/admin/widget-followers.js +37 -0
- package/dist/admin/widget-followers.js.map +1 -0
- package/dist/admin/widget-health.d.ts +3 -0
- package/dist/admin/widget-health.d.ts.map +1 -0
- package/dist/admin/widget-health.js +103 -0
- package/dist/admin/widget-health.js.map +1 -0
- package/dist/admin/widget-interactions.d.ts +4 -0
- package/dist/admin/widget-interactions.d.ts.map +1 -0
- package/dist/admin/widget-interactions.js +99 -0
- package/dist/admin/widget-interactions.js.map +1 -0
- package/dist/admin/widget-posting.d.ts +3 -0
- package/dist/admin/widget-posting.d.ts.map +1 -0
- package/dist/admin/widget-posting.js +111 -0
- package/dist/admin/widget-posting.js.map +1 -0
- package/dist/admin/widget-scheduled.d.ts +4 -0
- package/dist/admin/widget-scheduled.d.ts.map +1 -0
- package/dist/admin/widget-scheduled.js +30 -0
- package/dist/admin/widget-scheduled.js.map +1 -0
- package/dist/admin/widget-top-posts.d.ts +4 -0
- package/dist/admin/widget-top-posts.d.ts.map +1 -0
- package/dist/admin/widget-top-posts.js +55 -0
- package/dist/admin/widget-top-posts.js.map +1 -0
- package/dist/admin/widgets.d.ts +35 -0
- package/dist/admin/widgets.d.ts.map +1 -0
- package/dist/admin/widgets.js +103 -0
- package/dist/admin/widgets.js.map +1 -0
- package/dist/cms/app.d.ts.map +1 -1
- package/dist/cms/app.js +2 -1
- package/dist/cms/app.js.map +1 -1
- package/dist/cms/boot.d.ts.map +1 -1
- package/dist/cms/boot.js +3 -2
- package/dist/cms/boot.js.map +1 -1
- package/dist/cms/services.d.ts.map +1 -1
- package/dist/cms/services.js +19 -0
- package/dist/cms/services.js.map +1 -1
- package/dist/content/alt-text.d.ts +1 -0
- package/dist/content/alt-text.d.ts.map +1 -1
- package/dist/content/alt-text.js +26 -1
- package/dist/content/alt-text.js.map +1 -1
- package/dist/content/sqlite/catalog.d.ts.map +1 -1
- package/dist/content/sqlite/catalog.js +15 -2
- package/dist/content/sqlite/catalog.js.map +1 -1
- package/dist/content/store.d.ts +10 -0
- package/dist/content/store.d.ts.map +1 -1
- package/dist/content/store.js.map +1 -1
- package/dist/content/write.d.ts.map +1 -1
- package/dist/content/write.js +3 -1
- package/dist/content/write.js.map +1 -1
- package/dist/federation/backfill.d.ts +1 -1
- package/dist/federation/backfill.d.ts.map +1 -1
- package/dist/federation/backfill.js +5 -1
- package/dist/federation/backfill.js.map +1 -1
- package/dist/federation/follower-history.d.ts +16 -0
- package/dist/federation/follower-history.d.ts.map +1 -0
- package/dist/federation/follower-history.js +61 -0
- package/dist/federation/follower-history.js.map +1 -0
- package/dist/federation/inbox.d.ts.map +1 -1
- package/dist/federation/inbox.js +2 -1
- package/dist/federation/inbox.js.map +1 -1
- package/dist/federation/records.d.ts +1 -0
- package/dist/federation/records.d.ts.map +1 -1
- package/dist/federation/records.js +24 -6
- package/dist/federation/records.js.map +1 -1
- package/dist/files/data-files.d.ts +1 -0
- package/dist/files/data-files.d.ts.map +1 -1
- package/dist/files/data-files.js +6 -0
- package/dist/files/data-files.js.map +1 -1
- package/dist/jobs/queue.d.ts.map +1 -1
- package/dist/jobs/queue.js +5 -0
- package/dist/jobs/queue.js.map +1 -1
- package/dist/jobs/types.d.ts +7 -0
- package/dist/jobs/types.d.ts.map +1 -1
- package/dist/jobs/types.js.map +1 -1
- package/dist/media/library.d.ts +9 -0
- package/dist/media/library.d.ts.map +1 -1
- package/dist/media/library.js +25 -1
- package/dist/media/library.js.map +1 -1
- package/dist/plugin.d.ts +275 -21
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +9 -8
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/fetch.d.ts +0 -5
- package/dist/plugins/fetch.d.ts.map +1 -1
- package/dist/plugins/fetch.js +31 -7
- package/dist/plugins/fetch.js.map +1 -1
- package/dist/plugins/host-api.d.ts +3 -0
- package/dist/plugins/host-api.d.ts.map +1 -0
- package/dist/plugins/host-api.js +8 -0
- package/dist/plugins/host-api.js.map +1 -0
- package/dist/plugins/install.d.ts.map +1 -1
- package/dist/plugins/install.js +4 -2
- package/dist/plugins/install.js.map +1 -1
- package/dist/plugins/page-tags.d.ts +8 -0
- package/dist/plugins/page-tags.d.ts.map +1 -0
- package/dist/plugins/page-tags.js +73 -0
- package/dist/plugins/page-tags.js.map +1 -0
- package/dist/plugins/registry.d.ts +4 -1
- package/dist/plugins/registry.d.ts.map +1 -1
- package/dist/plugins/registry.js +50 -9
- package/dist/plugins/registry.js.map +1 -1
- package/dist/plugins/site.js +1 -1
- package/dist/plugins/site.js.map +1 -1
- package/dist/store/admin-store.d.ts +2 -2
- package/dist/store/admin-store.d.ts.map +1 -1
- package/dist/store/admin-store.js.map +1 -1
- package/dist/store/comments.d.ts +7 -0
- package/dist/store/comments.d.ts.map +1 -1
- package/dist/store/comments.js +21 -0
- package/dist/store/comments.js.map +1 -1
- package/dist/store/deliveries.d.ts +1 -0
- package/dist/store/deliveries.d.ts.map +1 -1
- package/dist/store/deliveries.js +6 -0
- package/dist/store/deliveries.js.map +1 -1
- package/dist/store/inbox.d.ts +16 -0
- package/dist/store/inbox.d.ts.map +1 -1
- package/dist/store/inbox.js +62 -0
- package/dist/store/inbox.js.map +1 -1
- package/dist/store/queue-database.d.ts +6 -0
- package/dist/store/queue-database.d.ts.map +1 -1
- package/dist/store/queue-database.js +16 -1
- package/dist/store/queue-database.js.map +1 -1
- package/dist/store/webmentions.d.ts +1 -0
- package/dist/store/webmentions.d.ts.map +1 -1
- package/dist/store/webmentions.js +6 -0
- package/dist/store/webmentions.js.map +1 -1
- package/dist/web/env.d.ts +3 -0
- package/dist/web/env.d.ts.map +1 -1
- package/dist/web/feed-item.d.ts +4 -3
- package/dist/web/feed-item.d.ts.map +1 -1
- package/dist/web/feed-item.js +8 -2
- package/dist/web/feed-item.js.map +1 -1
- package/dist/web/listing-pages.d.ts.map +1 -1
- package/dist/web/listing-pages.js +7 -2
- package/dist/web/listing-pages.js.map +1 -1
- package/dist/web/page-tags.d.ts +4 -0
- package/dist/web/page-tags.d.ts.map +1 -0
- package/dist/web/page-tags.js +39 -0
- package/dist/web/page-tags.js.map +1 -0
- package/dist/web/render.d.ts +2 -0
- package/dist/web/render.d.ts.map +1 -1
- package/dist/web/render.js +14 -0
- package/dist/web/render.js.map +1 -1
- package/dist/web/routes.d.ts +2 -1
- package/dist/web/routes.d.ts.map +1 -1
- package/dist/web/routes.js +3 -1
- package/dist/web/routes.js.map +1 -1
- package/package.json +6 -1
- package/themes/default/layouts/base.njk +6 -4
- package/dist/comments/routes.d.ts +0 -65
- package/dist/comments/routes.d.ts.map +0 -1
- package/dist/comments/routes.js +0 -235
- package/dist/comments/routes.js.map +0 -1
- package/dist/content/media.d.ts +0 -85
- package/dist/content/media.d.ts.map +0 -1
- package/dist/content/media.js +0 -237
- package/dist/content/media.js.map +0 -1
- package/dist/content/read-form.d.ts +0 -31
- package/dist/content/read-form.d.ts.map +0 -1
- package/dist/content/read-form.js +0 -157
- package/dist/content/read-form.js.map +0 -1
- package/dist/content/read.d.ts +0 -29
- package/dist/content/read.d.ts.map +0 -1
- package/dist/content/read.js +0 -82
- package/dist/content/read.js.map +0 -1
- package/dist/export/export-archives.d.ts +0 -29
- package/dist/export/export-archives.d.ts.map +0 -1
- package/dist/export/export-archives.js +0 -88
- package/dist/export/export-archives.js.map +0 -1
- package/dist/federation/mount.d.ts +0 -53
- package/dist/federation/mount.d.ts.map +0 -1
- package/dist/federation/mount.js +0 -344
- package/dist/federation/mount.js.map +0 -1
- package/dist/mail/credentials.d.ts +0 -62
- package/dist/mail/credentials.d.ts.map +0 -1
- package/dist/mail/credentials.js +0 -86
- package/dist/mail/credentials.js.map +0 -1
- package/dist/site/setting-rows.d.ts +0 -45
- package/dist/site/setting-rows.d.ts.map +0 -1
- package/dist/site/setting-rows.js +0 -361
- package/dist/site/setting-rows.js.map +0 -1
- package/dist/site/settings-form.d.ts +0 -30
- package/dist/site/settings-form.d.ts.map +0 -1
- package/dist/site/settings-form.js +0 -54
- package/dist/site/settings-form.js.map +0 -1
- package/dist/site/site-json.d.ts +0 -38
- package/dist/site/site-json.d.ts.map +0 -1
- package/dist/site/site-json.js +0 -69
- package/dist/site/site-json.js.map +0 -1
- package/dist/webmention/routes.d.ts +0 -37
- package/dist/webmention/routes.d.ts.map +0 -1
- package/dist/webmention/routes.js +0 -75
- package/dist/webmention/routes.js.map +0 -1
|
@@ -32,8 +32,10 @@
|
|
|
32
32
|
Two partials, empty here, are included outside every block so that no layout
|
|
33
33
|
can drop them: `partials/head-end.njk` last in <head> and
|
|
34
34
|
`partials/body-end.njk` last in <body>. A site theme fills either one to add
|
|
35
|
-
analytics or a widget to every page without overriding a layout.
|
|
36
|
-
|
|
35
|
+
analytics or a widget to every page without overriding a layout. Just
|
|
36
|
+
before each, `pluginTags.headEnd` and `pluginTags.bodyEnd` draw the tags the
|
|
37
|
+
running plugins add. The editor's preview in the admin sets `editorPreview`
|
|
38
|
+
and leaves all four out.
|
|
37
39
|
#}{% import "partials/feeds.njk" as feeds %}
|
|
38
40
|
{%- import "partials/menu.njk" as nav %}
|
|
39
41
|
{#- Whether this is the front page, which is the one page the header and the
|
|
@@ -262,7 +264,7 @@
|
|
|
262
264
|
<link rel="manifest" href="{{ "/manifest.webmanifest" | url }}">
|
|
263
265
|
{% include "partials/jsonld.njk" %}
|
|
264
266
|
{% endblock %}
|
|
265
|
-
{% if not editorPreview %}{% include "partials/head-end.njk" %}{% endif %}
|
|
267
|
+
{% if not editorPreview %}{{ pluginTags.headEnd }}{% include "partials/head-end.njk" %}{% endif %}
|
|
266
268
|
</head>
|
|
267
269
|
<body>
|
|
268
270
|
<a class="screen-reader-text" href="#main">Skip to content</a>
|
|
@@ -348,6 +350,6 @@
|
|
|
348
350
|
<script src="{{ "highlight.js" | asset }}" defer></script>
|
|
349
351
|
{% endif %}
|
|
350
352
|
{% endblock %}
|
|
351
|
-
{% if not editorPreview %}{% include "partials/body-end.njk" %}{% endif %}
|
|
353
|
+
{% if not editorPreview %}{{ pluginTags.bodyEnd }}{% include "partials/body-end.njk" %}{% endif %}
|
|
352
354
|
</body>
|
|
353
355
|
</html>
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Hono } from 'hono';
|
|
2
|
-
import type { AdminStore } from '../store/admin-store.ts';
|
|
3
|
-
import type { Document } from '../content/document.ts';
|
|
4
|
-
import type { GeekityEnv } from '../web/env.ts';
|
|
5
|
-
import type { CommentFormContext, CommentViewer } from './form.ts';
|
|
6
|
-
import type { Conversation } from './conversation.ts';
|
|
7
|
-
/**
|
|
8
|
-
* The one public endpoint comments add: where the form under a post posts to.
|
|
9
|
-
*
|
|
10
|
-
* It is a single path rather than one per post because the post is a field of
|
|
11
|
-
* the form. That keeps it out of the way of every permalink a site might ever
|
|
12
|
-
* mint — a path under `/_geekity/` is the CMS's own, like the health check —
|
|
13
|
-
* and means the route table does not grow with the site.
|
|
14
|
-
*
|
|
15
|
-
* Everything it answers is either a redirect or the post's own page rendered
|
|
16
|
-
* again with the form still filled in. There is no JSON, no fragment and no
|
|
17
|
-
* script: a comment form has worked without JavaScript since 2003 and there is
|
|
18
|
-
* no reason for this one to stop.
|
|
19
|
-
*/
|
|
20
|
-
export { COMMENT_POST_PATH, COMMENT_REPLY_PARAM } from './form.ts';
|
|
21
|
-
/** Register the comment endpoint. Mounted by the public site. */
|
|
22
|
-
export declare function mountComments(app: Hono<GeekityEnv>): void;
|
|
23
|
-
/**
|
|
24
|
-
* The thank-you a reader is shown after posting, from the query the redirect
|
|
25
|
-
* carried, or `undefined` when the URL says nothing.
|
|
26
|
-
*
|
|
27
|
-
* A query rather than a flash message, because a reader has no session to hang
|
|
28
|
-
* one on, and because a comment form that only works for people with cookies
|
|
29
|
-
* is not a comment form.
|
|
30
|
-
*/
|
|
31
|
-
export declare function commentNoticeFor(query: string | undefined): string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* The comment a `?reply_to=` query points at, as the theme needs it, or an
|
|
34
|
-
* empty object when the query names nothing on this post.
|
|
35
|
-
*
|
|
36
|
-
* Checked against the index rather than trusted, so a made-up id — or one from
|
|
37
|
-
* another page — cannot put a stranger's name on somebody's reply form, and so
|
|
38
|
-
* a comment waiting for a moderator cannot be discovered by guessing. With the
|
|
39
|
-
* post's `thread`, which is handed over for somebody signed in (TASK-300), any
|
|
40
|
-
* entry a reader can see is answerable: a webmention, a fediverse reply or a
|
|
41
|
-
* reply post as well as a comment.
|
|
42
|
-
*/
|
|
43
|
-
export declare function commentReplyTarget(options: {
|
|
44
|
-
admin: AdminStore;
|
|
45
|
-
document: Document;
|
|
46
|
-
id: string | undefined;
|
|
47
|
-
thread?: Conversation | undefined;
|
|
48
|
-
}): Record<string, unknown>;
|
|
49
|
-
/**
|
|
50
|
-
* The form for a post, or `undefined` when it is not taking comments.
|
|
51
|
-
*
|
|
52
|
-
* What the renderer is handed at boot. It reads the settings and the clock on
|
|
53
|
-
* every render, so a post that closed an hour ago stops offering a form on the
|
|
54
|
-
* very next request.
|
|
55
|
-
*/
|
|
56
|
-
export declare function commentFormFor(options: {
|
|
57
|
-
document: Document;
|
|
58
|
-
site: Record<string, unknown>;
|
|
59
|
-
now: Date;
|
|
60
|
-
/** Whether the site can send mail, which is whether the box is offered. */
|
|
61
|
-
notifiable?: boolean | undefined;
|
|
62
|
-
/** Who the request's session says is reading, when it says anybody. */
|
|
63
|
-
viewer?: CommentViewer | undefined;
|
|
64
|
-
}): CommentFormContext | undefined;
|
|
65
|
-
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/comments/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAahD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWtD;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEnE,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAkHzD;AA2DD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE9E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAe1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,IAAI,CAAC;IACV,2EAA2E;IAC3E,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,uEAAuE;IACvE,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACpC,GAAG,kBAAkB,GAAG,SAAS,CAKjC"}
|
package/dist/comments/routes.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { CROSS_SITE_REFUSAL, crossSiteWrite, csrfTokenMatches } from '../web/session.js';
|
|
2
|
-
import { clientAddress, createLoginThrottle } from '../web/throttle.js';
|
|
3
|
-
import { documentSite } from '../admin/documents.js';
|
|
4
|
-
import { stringOrEmpty } from '../util/forms.js';
|
|
5
|
-
import { isServed } from '../content/served.js';
|
|
6
|
-
import { COMMENT_NOTICE_PARAM, COMMENT_NOTICES, COMMENT_POST_PATH, commentForm, refilledCommentForm, signedInCommentForm, valuesOf, } from './form.js';
|
|
7
|
-
import { commentPolicyOf, commentsOpen } from './policy.js';
|
|
8
|
-
import { commentAnchor, visibleReply } from './conversation.js';
|
|
9
|
-
import { COMMENT_FIELDS, COMMENT_RATE_LIMIT, COMMENT_RATE_WINDOW_SECONDS, submitComment, } from './submission.js';
|
|
10
|
-
import { submitReplyPost } from './reply-post.js';
|
|
11
|
-
import { commenterOf } from './viewer.js';
|
|
12
|
-
/**
|
|
13
|
-
* The one public endpoint comments add: where the form under a post posts to.
|
|
14
|
-
*
|
|
15
|
-
* It is a single path rather than one per post because the post is a field of
|
|
16
|
-
* the form. That keeps it out of the way of every permalink a site might ever
|
|
17
|
-
* mint — a path under `/_geekity/` is the CMS's own, like the health check —
|
|
18
|
-
* and means the route table does not grow with the site.
|
|
19
|
-
*
|
|
20
|
-
* Everything it answers is either a redirect or the post's own page rendered
|
|
21
|
-
* again with the form still filled in. There is no JSON, no fragment and no
|
|
22
|
-
* script: a comment form has worked without JavaScript since 2003 and there is
|
|
23
|
-
* no reason for this one to stop.
|
|
24
|
-
*/
|
|
25
|
-
export { COMMENT_POST_PATH, COMMENT_REPLY_PARAM } from './form.js';
|
|
26
|
-
/** Register the comment endpoint. Mounted by the public site. */
|
|
27
|
-
export function mountComments(app) {
|
|
28
|
-
// One limiter for the whole mount, built on the first submission because the
|
|
29
|
-
// clock is on the context. It holds nothing but recent submissions, so it
|
|
30
|
-
// belongs to the process rather than the database: a restart clears it,
|
|
31
|
-
// which is the right trade for state an anonymous caller can create.
|
|
32
|
-
let limiter;
|
|
33
|
-
function throttle(config) {
|
|
34
|
-
limiter ??= createLoginThrottle({
|
|
35
|
-
attempts: COMMENT_RATE_LIMIT,
|
|
36
|
-
lockoutSeconds: COMMENT_RATE_WINDOW_SECONDS,
|
|
37
|
-
now: config.now,
|
|
38
|
-
});
|
|
39
|
-
return limiter;
|
|
40
|
-
}
|
|
41
|
-
app.post(COMMENT_POST_PATH, async (c) => {
|
|
42
|
-
const { store, admin, renderer, config } = c.var;
|
|
43
|
-
const body = await c.req.parseBody();
|
|
44
|
-
const form = formOf(body);
|
|
45
|
-
// Who the session says this is, read before anything else is decided: it
|
|
46
|
-
// settles the token, the attribution and where the comment lands.
|
|
47
|
-
const account = c.var.signedIn;
|
|
48
|
-
const viewer = account === undefined ? undefined : commenterOf(account);
|
|
49
|
-
// A form that acts on nobody's behalf needs no token, and the public one
|
|
50
|
-
// still carries none. This one posts under somebody's name, so without a
|
|
51
|
-
// matching token a page on another site could make them say something they
|
|
52
|
-
// never typed. Refused in the words and with the status the admin guard
|
|
53
|
-
// uses, because it is the same check on the same token.
|
|
54
|
-
//
|
|
55
|
-
// Fetch Metadata first, as in the admin: a browser that says the form was
|
|
56
|
-
// on another site is refused whatever token it carries. A stranger's form
|
|
57
|
-
// is left alone, because it acts on nobody's behalf.
|
|
58
|
-
if (viewer !== undefined && crossSiteWrite(c))
|
|
59
|
-
return c.text(CROSS_SITE_REFUSAL, 403);
|
|
60
|
-
if (viewer !== undefined && !csrfTokenMatches(viewer.csrfToken, form.csrf)) {
|
|
61
|
-
return c.text('That form was stale or came from somewhere else. Reload and try again.', 403);
|
|
62
|
-
}
|
|
63
|
-
const document = store.getBySlug(form.post);
|
|
64
|
-
if (document === undefined || !isServed(document, store.now())) {
|
|
65
|
-
return c.text('There is no such post to comment on.', 404);
|
|
66
|
-
}
|
|
67
|
-
const now = config.now();
|
|
68
|
-
if (!commentsOpen(document, commentPolicyOf(renderer.site()), now)) {
|
|
69
|
-
// 403 rather than 404: the post is there, and the reader can see for
|
|
70
|
-
// themselves that it is. Saying so is more honest than pretending the
|
|
71
|
-
// URL is wrong, and a closed post is a state rather than a mistake.
|
|
72
|
-
return page(c, document, 403, viewer, {
|
|
73
|
-
...drawnFor(refilledCommentForm(document, valuesOf(form), {}, now), viewer),
|
|
74
|
-
error: 'This post is not taking comments any more.',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (viewer !== undefined) {
|
|
78
|
-
const answered = await submitReplyPost({
|
|
79
|
-
site: documentSite(c, viewer.username),
|
|
80
|
-
document,
|
|
81
|
-
conversation: c.var.conversation.thread(document),
|
|
82
|
-
form,
|
|
83
|
-
throttle: throttle(config),
|
|
84
|
-
address: clientAddress(c, config),
|
|
85
|
-
});
|
|
86
|
-
if (answered.kind === 'saved') {
|
|
87
|
-
const reply = c.var.conversation.replyNamed(document, answered.saved.permalink);
|
|
88
|
-
const anchor = reply === undefined ? 'comments' : commentAnchor(reply.key);
|
|
89
|
-
return c.redirect(`${document.permalink}?${COMMENT_NOTICE_PARAM}=posted#${anchor}`, 303);
|
|
90
|
-
}
|
|
91
|
-
return refusedPage(c, document, viewer, form, answered.refusal, now);
|
|
92
|
-
}
|
|
93
|
-
const outcome = await submitComment({
|
|
94
|
-
records: { admin, contentDir: config.contentDir, dataDir: config.dataDir },
|
|
95
|
-
document,
|
|
96
|
-
cited: (url) => c.var.replyContexts.read(url),
|
|
97
|
-
form,
|
|
98
|
-
dataDir: config.dataDir,
|
|
99
|
-
baseUrl: config.baseUrl,
|
|
100
|
-
checker: config.commentChecker,
|
|
101
|
-
// Who hears about what lands is the intake's to decide, and neither
|
|
102
|
-
// message is awaited: the reader is redirected now and they go out
|
|
103
|
-
// behind them (TASK-55).
|
|
104
|
-
notices: c.var.notifications,
|
|
105
|
-
address: clientAddress(c, config),
|
|
106
|
-
userAgent: c.req.header('user-agent'),
|
|
107
|
-
referrer: c.req.header('referer'),
|
|
108
|
-
throttle: throttle(config),
|
|
109
|
-
// Whether the box on the form meant anything, read per submission so a
|
|
110
|
-
// credential saved a moment ago is honoured now (TASK-55).
|
|
111
|
-
notifiable: c.var.mail.configured(),
|
|
112
|
-
now,
|
|
113
|
-
});
|
|
114
|
-
if (outcome.kind === 'stored') {
|
|
115
|
-
const stored = outcome.comment;
|
|
116
|
-
// A redirect rather than a rendered page, so a refresh does not post the
|
|
117
|
-
// comment a second time. An approved comment is on the page already, so
|
|
118
|
-
// the reader is sent to it; one waiting for a moderator has nothing to
|
|
119
|
-
// point at, so the reader is sent to the form they just used.
|
|
120
|
-
const anchor = stored.status === 'approved' ? commentAnchor(stored.id) : 'respond';
|
|
121
|
-
const notice = stored.status === 'approved' ? 'posted' : 'pending';
|
|
122
|
-
return c.redirect(`${document.permalink}?${COMMENT_NOTICE_PARAM}=${notice}#${anchor}`, 303);
|
|
123
|
-
}
|
|
124
|
-
const refusal = outcome.refusal;
|
|
125
|
-
if (refusal.kind === 'discarded') {
|
|
126
|
-
// Nothing is said about why. A robot that filled the honeypot, or that a
|
|
127
|
-
// checker recognised, learns exactly as much from this as from a
|
|
128
|
-
// successful post — which is the point of both defences.
|
|
129
|
-
return c.redirect(`${document.permalink}?${COMMENT_NOTICE_PARAM}=pending#respond`, 303);
|
|
130
|
-
}
|
|
131
|
-
return refusedPage(c, document, viewer, form, refusal, now);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/** The post's page again, with the form refilled and what went wrong on it. */
|
|
135
|
-
function refusedPage(c, document, viewer, form, refusal, now) {
|
|
136
|
-
if (refusal.kind === 'rate-limited') {
|
|
137
|
-
c.header('Retry-After', String(refusal.retryAfter));
|
|
138
|
-
return page(c, document, 429, viewer, {
|
|
139
|
-
...drawnFor(refilledCommentForm(document, valuesOf(form), {}, now), viewer),
|
|
140
|
-
error: 'That is a lot of comments in a short time. Try again in a few minutes.',
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
const message = refusal.kind === 'too-quick'
|
|
144
|
-
? 'That was posted faster than anybody types. Try again.'
|
|
145
|
-
: refusal.kind === 'stale'
|
|
146
|
-
? 'That form had been open a long time. Here it is again — the words are still there.'
|
|
147
|
-
: undefined;
|
|
148
|
-
return page(c, document, 400, viewer, {
|
|
149
|
-
...drawnFor(refilledCommentForm(document, valuesOf(form), problemsOf(refusal), now), viewer),
|
|
150
|
-
...(message === undefined ? {} : { error: message }),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* The same form drawn for whoever is filling it in: the short one when the
|
|
155
|
-
* site knows them, and the stranger's one when it does not.
|
|
156
|
-
*/
|
|
157
|
-
function drawnFor(form, viewer) {
|
|
158
|
-
return viewer === undefined ? form : signedInCommentForm(form, viewer);
|
|
159
|
-
}
|
|
160
|
-
function page(c, document, status, viewer, form) {
|
|
161
|
-
c.status(status);
|
|
162
|
-
return c.html(c.var.renderer.renderDocument(document, { commentForm: form }, viewer));
|
|
163
|
-
}
|
|
164
|
-
/** The per-field messages a refusal carries, if it carries any. */
|
|
165
|
-
function problemsOf(refusal) {
|
|
166
|
-
return refusal.kind === 'invalid' ? (refusal.problems ?? {}) : {};
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* The thank-you a reader is shown after posting, from the query the redirect
|
|
170
|
-
* carried, or `undefined` when the URL says nothing.
|
|
171
|
-
*
|
|
172
|
-
* A query rather than a flash message, because a reader has no session to hang
|
|
173
|
-
* one on, and because a comment form that only works for people with cookies
|
|
174
|
-
* is not a comment form.
|
|
175
|
-
*/
|
|
176
|
-
export function commentNoticeFor(query) {
|
|
177
|
-
return query === undefined ? undefined : COMMENT_NOTICES[query];
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* The comment a `?reply_to=` query points at, as the theme needs it, or an
|
|
181
|
-
* empty object when the query names nothing on this post.
|
|
182
|
-
*
|
|
183
|
-
* Checked against the index rather than trusted, so a made-up id — or one from
|
|
184
|
-
* another page — cannot put a stranger's name on somebody's reply form, and so
|
|
185
|
-
* a comment waiting for a moderator cannot be discovered by guessing. With the
|
|
186
|
-
* post's `thread`, which is handed over for somebody signed in (TASK-300), any
|
|
187
|
-
* entry a reader can see is answerable: a webmention, a fediverse reply or a
|
|
188
|
-
* reply post as well as a comment.
|
|
189
|
-
*/
|
|
190
|
-
export function commentReplyTarget(options) {
|
|
191
|
-
if (options.id === undefined || options.id === '')
|
|
192
|
-
return {};
|
|
193
|
-
if (options.thread !== undefined) {
|
|
194
|
-
const reply = visibleReply(options.thread.replies, options.id);
|
|
195
|
-
return reply === undefined
|
|
196
|
-
? {}
|
|
197
|
-
: { commentReplyTo: reply.key, commentReplyingTo: reply.author.name };
|
|
198
|
-
}
|
|
199
|
-
const parent = options.admin.getComment(options.id);
|
|
200
|
-
if (parent === undefined || parent.slug !== options.document.slug)
|
|
201
|
-
return {};
|
|
202
|
-
if (parent.status !== 'approved')
|
|
203
|
-
return {};
|
|
204
|
-
return { commentReplyTo: parent.id, commentReplyingTo: parent.author.name };
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* The form for a post, or `undefined` when it is not taking comments.
|
|
208
|
-
*
|
|
209
|
-
* What the renderer is handed at boot. It reads the settings and the clock on
|
|
210
|
-
* every render, so a post that closed an hour ago stops offering a form on the
|
|
211
|
-
* very next request.
|
|
212
|
-
*/
|
|
213
|
-
export function commentFormFor(options) {
|
|
214
|
-
if (!commentsOpen(options.document, commentPolicyOf(options.site), options.now))
|
|
215
|
-
return undefined;
|
|
216
|
-
const form = commentForm(options.document, options.now, options.notifiable ?? false);
|
|
217
|
-
return drawnFor(form, options.viewer);
|
|
218
|
-
}
|
|
219
|
-
/** A submitted body as the form it is, every field a string. */
|
|
220
|
-
function formOf(body) {
|
|
221
|
-
return {
|
|
222
|
-
post: stringOrEmpty(body[COMMENT_FIELDS.post]),
|
|
223
|
-
name: stringOrEmpty(body[COMMENT_FIELDS.name]),
|
|
224
|
-
email: stringOrEmpty(body[COMMENT_FIELDS.email]),
|
|
225
|
-
url: stringOrEmpty(body[COMMENT_FIELDS.url]),
|
|
226
|
-
body: stringOrEmpty(body[COMMENT_FIELDS.body]),
|
|
227
|
-
inReplyTo: stringOrEmpty(body[COMMENT_FIELDS.inReplyTo]),
|
|
228
|
-
trap: stringOrEmpty(body[COMMENT_FIELDS.trap]),
|
|
229
|
-
loaded: stringOrEmpty(body[COMMENT_FIELDS.loaded]),
|
|
230
|
-
notify: stringOrEmpty(body[COMMENT_FIELDS.notify]),
|
|
231
|
-
csrf: stringOrEmpty(body[COMMENT_FIELDS.csrf]),
|
|
232
|
-
listed: stringOrEmpty(body[COMMENT_FIELDS.listed]),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
//# sourceMappingURL=routes.js.map
|
|
@@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content/media.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What may be uploaded into `content/uploads/`, described once.
|
|
3
|
-
*
|
|
4
|
-
* The upload endpoint is the only door into the content directory that does
|
|
5
|
-
* not write Markdown, so what it accepts is a list rather than a judgement:
|
|
6
|
-
* an extension the CMS has never heard of is refused, and one it has is
|
|
7
|
-
* checked against the media type the browser declared and, where the format
|
|
8
|
-
* has one, against the bytes the file actually starts with.
|
|
9
|
-
*
|
|
10
|
-
* The table lives here rather than beside the endpoint because
|
|
11
|
-
* {@link ResolvedConfig} validates a site's allowlist against it, and config
|
|
12
|
-
* may not depend on the admin.
|
|
13
|
-
*/
|
|
14
|
-
/** Bytes a file of some format carries at a fixed offset. */
|
|
15
|
-
export interface UploadSignature {
|
|
16
|
-
/** Where in the file the bytes are. */
|
|
17
|
-
offset: number;
|
|
18
|
-
/** The bytes themselves. */
|
|
19
|
-
bytes: readonly number[];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* What an upload is for, which decides what the CMS offers to do with it.
|
|
23
|
-
*
|
|
24
|
-
* An image is embedded and gets variants, audio and video can be a post's
|
|
25
|
-
* enclosure and are held to their own size limit, and a document is linked.
|
|
26
|
-
*/
|
|
27
|
-
export type UploadKind = 'image' | 'audio' | 'video' | 'document';
|
|
28
|
-
/** One kind of file the upload endpoint knows about. */
|
|
29
|
-
export interface UploadMediaType {
|
|
30
|
-
/**
|
|
31
|
-
* Media types a browser may declare for this extension. An empty string is
|
|
32
|
-
* always accepted alongside these: a browser that does not recognise a file
|
|
33
|
-
* sends no type at all, and there is then nothing to disagree with.
|
|
34
|
-
*/
|
|
35
|
-
declared: readonly string[];
|
|
36
|
-
/** What the file is for. */
|
|
37
|
-
kind: UploadKind;
|
|
38
|
-
/**
|
|
39
|
-
* Byte patterns that identify the format, as alternatives: a file matches
|
|
40
|
-
* when every part of any one of them matches. Absent for the text formats,
|
|
41
|
-
* which have no header to check.
|
|
42
|
-
*/
|
|
43
|
-
signatures?: readonly (readonly UploadSignature[])[] | undefined;
|
|
44
|
-
/** Whether the file is text, served with its character set named. */
|
|
45
|
-
text?: true;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Every extension the upload endpoint can accept, and what it takes to be one.
|
|
49
|
-
*
|
|
50
|
-
* SVG is deliberately absent. An SVG is a document that may carry script, and
|
|
51
|
-
* an upload is served from the site's own origin, so accepting one would hand
|
|
52
|
-
* anybody who can reach the editor a stored cross-site scripting hole. A site
|
|
53
|
-
* that wants them anyway can put `.svg` in `uploadTypes` — and then it has
|
|
54
|
-
* chosen that, which is the point.
|
|
55
|
-
*/
|
|
56
|
-
export declare const UPLOAD_MEDIA_TYPES: ReadonlyMap<string, UploadMediaType>;
|
|
57
|
-
/** The extensions a site may put in its allowlist, sorted. */
|
|
58
|
-
export declare const KNOWN_UPLOAD_TYPES: readonly string[];
|
|
59
|
-
/**
|
|
60
|
-
* An extension as the allowlist spells it: lower case, with the dot.
|
|
61
|
-
*
|
|
62
|
-
* `PNG`, `.Png` and `png` are all the same thing to somebody writing a config
|
|
63
|
-
* file, so they are the same thing here.
|
|
64
|
-
*/
|
|
65
|
-
export declare function normalizeUploadType(value: string): string;
|
|
66
|
-
/**
|
|
67
|
-
* The media type a feed or an attachment announces for this kind of file: the
|
|
68
|
-
* first one {@link UploadMediaType.declared} lists, which is the registered
|
|
69
|
-
* name where a browser may also send an older one.
|
|
70
|
-
*/
|
|
71
|
-
export declare function canonicalType(media: UploadMediaType): string | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* The `Content-Type` an upload of this kind is served with: its
|
|
74
|
-
* {@link canonicalType}, with the character set when it is text.
|
|
75
|
-
*/
|
|
76
|
-
export declare function servedType(media: UploadMediaType): string;
|
|
77
|
-
/**
|
|
78
|
-
* Whether the first bytes of a file are the ones its extension implies.
|
|
79
|
-
*
|
|
80
|
-
* A format with no signature — the text ones — matches anything, because there
|
|
81
|
-
* is nothing to compare. Returns `false` for a file too short to hold the
|
|
82
|
-
* header it claims.
|
|
83
|
-
*/
|
|
84
|
-
export declare function matchesSignature(media: UploadMediaType, bytes: Uint8Array): boolean;
|
|
85
|
-
//# sourceMappingURL=media.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/content/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AAElE,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,eAAe,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC;IACjE,qEAAqE;IACrE,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAgBD;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAkKlE,CAAC;AAEH,8DAA8D;AAC9D,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAA0C,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAExE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAGzD;AAED;;;;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