@velocity-astro/cms-plugins 0.0.0-stage → 0.1.0-beta.11
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 +12 -2
- package/dist/hubspot/plugin.d.ts +10 -0
- package/dist/hubspot/plugin.d.ts.map +1 -0
- package/dist/hubspot/plugin.js +92 -0
- package/dist/hubspot/plugin.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mailchimp/plugin.d.ts +14 -0
- package/dist/mailchimp/plugin.d.ts.map +1 -0
- package/dist/mailchimp/plugin.js +128 -0
- package/dist/mailchimp/plugin.js.map +1 -0
- package/dist/seo/analyse.d.ts +40 -0
- package/dist/seo/analyse.d.ts.map +1 -0
- package/dist/seo/analyse.js +34 -0
- package/dist/seo/analyse.js.map +1 -0
- package/dist/seo/editor.d.ts +20 -0
- package/dist/seo/editor.d.ts.map +1 -0
- package/dist/seo/editor.js +189 -0
- package/dist/seo/editor.js.map +1 -0
- package/dist/seo/plugin.d.ts +7 -0
- package/dist/seo/plugin.d.ts.map +1 -0
- package/dist/seo/plugin.js +156 -0
- package/dist/seo/plugin.js.map +1 -0
- package/dist/slack/plugin.d.ts +13 -0
- package/dist/slack/plugin.d.ts.map +1 -0
- package/dist/slack/plugin.js +98 -0
- package/dist/slack/plugin.js.map +1 -0
- package/dist/webhooks/plugin.d.ts +14 -0
- package/dist/webhooks/plugin.d.ts.map +1 -0
- package/dist/webhooks/plugin.js +161 -0
- package/dist/webhooks/plugin.js.map +1 -0
- package/package.json +34 -3
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SEO plugin's part of the editor: a search preview beside every entry that has a page of its own, and a screen that
|
|
3
|
+
* lists what needs attention across the site.
|
|
4
|
+
*
|
|
5
|
+
* This function is sent to the browser as text (see `plugin.ts`), so it must stand alone: it may
|
|
6
|
+
* use nothing but its two arguments, and no helper from this file or any other.
|
|
7
|
+
*/
|
|
8
|
+
export function seoEditor({ React, ui, client, links, register }, analyse) {
|
|
9
|
+
const h = React.createElement;
|
|
10
|
+
const { Button, Card, EmptyState, Inline, Link, Skeleton, Stack, Switch, Table, Tag, Text, TextArea, TextField } = ui;
|
|
11
|
+
const WORDS = {
|
|
12
|
+
'no-title': 'No title',
|
|
13
|
+
'long-title': 'Title too long',
|
|
14
|
+
'no-description': 'No description',
|
|
15
|
+
'long-description': 'Description too long',
|
|
16
|
+
};
|
|
17
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
18
|
+
/** The plugin's settings, asked for once and again whenever a panel or the screen is opened. */
|
|
19
|
+
function useConfig() {
|
|
20
|
+
const [config, setConfig] = React.useState(null);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
let isCurrent = true;
|
|
23
|
+
client.get('/config').then((answer) => isCurrent && setConfig(answer), () => undefined);
|
|
24
|
+
return () => {
|
|
25
|
+
isCurrent = false;
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
const EMPTY = { title: '', description: '', hidden: false };
|
|
31
|
+
const toWritten = (answer) => {
|
|
32
|
+
const given = (typeof answer === 'object' && answer !== null ? answer : {});
|
|
33
|
+
return { title: given.title ?? '', description: given.description ?? '', hidden: given.hidden === true };
|
|
34
|
+
};
|
|
35
|
+
const SearchPreview = ({ type, entry, data }) => {
|
|
36
|
+
const config = useConfig();
|
|
37
|
+
const entryId = entry?.id ?? null;
|
|
38
|
+
// What is saved for this entry, and what is typed over it and not saved yet.
|
|
39
|
+
const [saved, setSaved] = React.useState(entryId === null ? EMPTY : null);
|
|
40
|
+
const [typed, setTyped] = React.useState(EMPTY);
|
|
41
|
+
const [isSaving, setSaving] = React.useState(false);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (entryId === null)
|
|
44
|
+
return undefined;
|
|
45
|
+
let isCurrent = true;
|
|
46
|
+
client.get(`/entries/${encodeURIComponent(entryId)}`).then((answer) => {
|
|
47
|
+
if (!isCurrent)
|
|
48
|
+
return;
|
|
49
|
+
setSaved(toWritten(answer));
|
|
50
|
+
setTyped(toWritten(answer));
|
|
51
|
+
},
|
|
52
|
+
// The preview still works from the entry's own fields.
|
|
53
|
+
() => isCurrent && setSaved(EMPTY));
|
|
54
|
+
return () => {
|
|
55
|
+
isCurrent = false;
|
|
56
|
+
};
|
|
57
|
+
}, [entryId]);
|
|
58
|
+
if (config === null || saved === null)
|
|
59
|
+
return h(Stack, { gap: 2, children: [h(Skeleton, { key: 'a', width: '1/3' }), h(Skeleton, { key: 'b', width: '1/4' })] });
|
|
60
|
+
const found = analyse(type, data, config, typed);
|
|
61
|
+
const has = (problem) => found.problems.includes(problem);
|
|
62
|
+
const hasChanges = typed.title !== saved.title || typed.description !== saved.description || typed.hidden !== saved.hidden;
|
|
63
|
+
const save = () => {
|
|
64
|
+
if (entryId === null)
|
|
65
|
+
return;
|
|
66
|
+
setSaving(true);
|
|
67
|
+
client
|
|
68
|
+
.put(`/entries/${encodeURIComponent(entryId)}`, { title: typed.title, description: typed.description, hidden: typed.hidden })
|
|
69
|
+
.then((answer) => {
|
|
70
|
+
setSaved(toWritten(answer));
|
|
71
|
+
setTyped(toWritten(answer));
|
|
72
|
+
ui.toast({ title: 'Saved for search engines', description: 'The page on the site shows it now.', tone: 'success' });
|
|
73
|
+
}, (error) => ui.toast({ title: 'This was not saved', description: messageOf(error), tone: 'danger' }))
|
|
74
|
+
.finally(() => setSaving(false));
|
|
75
|
+
};
|
|
76
|
+
return h(Stack, {
|
|
77
|
+
gap: 4,
|
|
78
|
+
children: [
|
|
79
|
+
h(Stack, {
|
|
80
|
+
key: 'preview',
|
|
81
|
+
gap: 1,
|
|
82
|
+
children: [
|
|
83
|
+
h(Text, { key: 'title', weight: 'semibold', children: found.title === '' ? 'No title yet' : found.title }),
|
|
84
|
+
h(Text, {
|
|
85
|
+
key: 'description',
|
|
86
|
+
size: 'sm',
|
|
87
|
+
tone: 'muted',
|
|
88
|
+
children: found.description !== '' ? found.description : 'No description yet. Search engines will choose text from the page.',
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
h(Inline, {
|
|
93
|
+
key: 'counts',
|
|
94
|
+
gap: 2,
|
|
95
|
+
children: [
|
|
96
|
+
h(Tag, { key: 'title', tone: has('no-title') || has('long-title') ? 'warning' : 'success', children: `Title ${found.title.length} of ${config.maxTitle}` }),
|
|
97
|
+
h(Tag, {
|
|
98
|
+
key: 'description',
|
|
99
|
+
tone: has('no-description') || has('long-description') ? 'warning' : found.description === '' ? 'neutral' : 'success',
|
|
100
|
+
children: `Description ${found.description.length} of ${config.maxDescription}`,
|
|
101
|
+
}),
|
|
102
|
+
typed.hidden && h(Tag, { key: 'hidden', tone: 'warning', children: 'Hidden from search' }),
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
entryId === null
|
|
106
|
+
? h(Text, { key: 'later', size: 'sm', tone: 'muted', children: 'Save the entry, then you can write a title and description just for search engines.' })
|
|
107
|
+
: h(Stack, {
|
|
108
|
+
key: 'written',
|
|
109
|
+
gap: 3,
|
|
110
|
+
children: [
|
|
111
|
+
h(TextField, {
|
|
112
|
+
key: 'title',
|
|
113
|
+
label: 'Search title',
|
|
114
|
+
description: found.ownTitle === '' ? 'Shown in search results.' : `Leave empty to use "${found.ownTitle}".`,
|
|
115
|
+
value: typed.title,
|
|
116
|
+
onChange: (title) => setTyped((current) => ({ ...current, title })),
|
|
117
|
+
}),
|
|
118
|
+
h(TextArea, {
|
|
119
|
+
key: 'description',
|
|
120
|
+
label: 'Search description',
|
|
121
|
+
description: found.ownDescription === '' ? 'One or two sentences shown under the title.' : 'Leave empty to use the entry\'s own description.',
|
|
122
|
+
value: typed.description,
|
|
123
|
+
onChange: (description) => setTyped((current) => ({ ...current, description })),
|
|
124
|
+
}),
|
|
125
|
+
h(Switch, { key: 'hidden', label: 'Hide this page from search engines', isSelected: typed.hidden, onChange: (hidden) => setTyped((current) => ({ ...current, hidden })) }),
|
|
126
|
+
h(Inline, {
|
|
127
|
+
key: 'save',
|
|
128
|
+
gap: 3,
|
|
129
|
+
children: [
|
|
130
|
+
h(Button, { key: 'button', variant: 'secondary', size: 'sm', isDisabled: !hasChanges || isSaving, isPending: isSaving, onPress: save, children: 'Save for search' }),
|
|
131
|
+
h(Text, { key: 'note', size: 'sm', tone: 'muted', children: 'Shows on the site at once.' }),
|
|
132
|
+
],
|
|
133
|
+
}),
|
|
134
|
+
],
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
function ReviewScreen() {
|
|
140
|
+
const [state, setState] = React.useState({ status: 'loading' });
|
|
141
|
+
const load = React.useCallback(() => {
|
|
142
|
+
setState({ status: 'loading' });
|
|
143
|
+
client.get('/review').then((answer) => setState({ status: 'done', ...answer }), (error) => setState({ status: 'failed', message: messageOf(error) }));
|
|
144
|
+
}, []);
|
|
145
|
+
React.useEffect(load, [load]);
|
|
146
|
+
if (state.status === 'loading') {
|
|
147
|
+
return h(Card, { children: h(Stack, { gap: 5, children: [0, 1, 2].map((row) => h(Skeleton, { key: row, width: row === 1 ? '1/4' : '1/3' })) }) });
|
|
148
|
+
}
|
|
149
|
+
if (state.status === 'failed') {
|
|
150
|
+
return h(EmptyState, { title: 'The review could not be read', description: state.message, action: h(Button, { variant: 'secondary', onPress: load, children: 'Try again' }) });
|
|
151
|
+
}
|
|
152
|
+
if (state.items.length === 0) {
|
|
153
|
+
return h(EmptyState, { title: 'Nothing to fix', description: `All ${state.checked} entries have a title and a description that fit.` });
|
|
154
|
+
}
|
|
155
|
+
return h(Stack, {
|
|
156
|
+
gap: 4,
|
|
157
|
+
children: [
|
|
158
|
+
h(Inline, {
|
|
159
|
+
key: 'top',
|
|
160
|
+
justify: 'between',
|
|
161
|
+
children: [
|
|
162
|
+
h(Text, { key: 'count', tone: 'muted', children: `${state.items.length} of ${state.checked} entries need attention.` }),
|
|
163
|
+
h(Button, { key: 'again', variant: 'secondary', size: 'sm', onPress: load, children: 'Check again' }),
|
|
164
|
+
],
|
|
165
|
+
}),
|
|
166
|
+
h(Table, {
|
|
167
|
+
key: 'table',
|
|
168
|
+
label: 'Entries that need attention',
|
|
169
|
+
columns: [
|
|
170
|
+
{ id: 'name', label: 'Entry' },
|
|
171
|
+
{ id: 'type', label: 'Type' },
|
|
172
|
+
{ id: 'problems', label: 'To fix' },
|
|
173
|
+
],
|
|
174
|
+
rows: state.items.map((item) => ({
|
|
175
|
+
id: item.id,
|
|
176
|
+
cells: {
|
|
177
|
+
name: h(Link, { href: links.entry(item.typeKey, item.id), children: item.name }),
|
|
178
|
+
type: h(Text, { size: 'sm', tone: 'muted', children: item.typeLabel }),
|
|
179
|
+
problems: h(Inline, { gap: 2, children: item.problems.map((problem) => h(Tag, { key: problem, tone: 'warning', children: WORDS[problem] })) }),
|
|
180
|
+
},
|
|
181
|
+
})),
|
|
182
|
+
}),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
register.entryPanel({ id: 'preview', title: 'Search preview', pagesOnly: true, Component: SearchPreview });
|
|
187
|
+
register.screen({ id: 'review', label: 'SEO', description: 'Titles and descriptions that search engines will show, and which entries still need one.', Component: ReviewScreen });
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../../src/seo/editor.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAmB,EAAE,OAAuB;IACxG,MAAM,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC;IAC9B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAA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a,EAAE,CAAC,CAAC;IAC3G,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,0FAA0F,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;AACpL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO: how each entry will read in search results. It shows a preview beside every entry, lists
|
|
3
|
+
* the entries that still need a title or a description, and can hold a publish back until the
|
|
4
|
+
* description is written. Built on the plugin surface alone, as any plugin is.
|
|
5
|
+
*/
|
|
6
|
+
export declare const seo: import("@velocity-astro/cms-core").PluginDefinition;
|
|
7
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/seo/plugin.ts"],"names":[],"mappings":"AA6DA;;;;GAIG;AACH,eAAO,MAAM,GAAG,qDAiGd,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ValidationError, definePlugin, hasOwnPages, liveFields } from '@velocity-astro/cms-core';
|
|
2
|
+
import { analyse } from './analyse.js';
|
|
3
|
+
import { seoEditor } from './editor.js';
|
|
4
|
+
/** What search engines show before they cut a title or a description short, near enough. */
|
|
5
|
+
const MAX_TITLE = 60;
|
|
6
|
+
const MAX_DESCRIPTION = 160;
|
|
7
|
+
/** The keys a description field usually has, when the owner names none. */
|
|
8
|
+
const DESCRIPTION_KEYS = ['description', 'summary', 'excerpt', 'intro'];
|
|
9
|
+
/** How many entries of one type the review reads. More than this and the list says so by its count. */
|
|
10
|
+
const REVIEWED_PER_TYPE = 500;
|
|
11
|
+
const textOf = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
12
|
+
/** Where what was written for one entry is kept in the plugin's store. */
|
|
13
|
+
const WRITTEN = 'written:';
|
|
14
|
+
const LONGEST_TITLE = 200;
|
|
15
|
+
const LONGEST_DESCRIPTION = 500;
|
|
16
|
+
/** What is kept for an entry, read back with nothing taken on trust. */
|
|
17
|
+
function writtenOf(stored) {
|
|
18
|
+
if (typeof stored !== 'object' || stored === null)
|
|
19
|
+
return {};
|
|
20
|
+
const { title, description, hidden } = stored;
|
|
21
|
+
return { ...(textOf(title) !== '' && { title: textOf(title) }), ...(textOf(description) !== '' && { description: textOf(description) }), ...(hidden === true && { hidden: true }) };
|
|
22
|
+
}
|
|
23
|
+
/** Checks what the editor sent for an entry, and says which part is wrong. */
|
|
24
|
+
function checked(body) {
|
|
25
|
+
const given = typeof body === 'object' && body !== null ? body : {};
|
|
26
|
+
const issues = [
|
|
27
|
+
...(given['title'] !== undefined && typeof given['title'] !== 'string' ? [{ path: ['title'], message: 'The search title must be text.' }] : []),
|
|
28
|
+
...(textOf(given['title']).length > LONGEST_TITLE ? [{ path: ['title'], message: `The search title can be at most ${LONGEST_TITLE} characters.` }] : []),
|
|
29
|
+
...(given['description'] !== undefined && typeof given['description'] !== 'string' ? [{ path: ['description'], message: 'The search description must be text.' }] : []),
|
|
30
|
+
...(textOf(given['description']).length > LONGEST_DESCRIPTION ? [{ path: ['description'], message: `The search description can be at most ${LONGEST_DESCRIPTION} characters.` }] : []),
|
|
31
|
+
...(given['hidden'] !== undefined && typeof given['hidden'] !== 'boolean' ? [{ path: ['hidden'], message: 'Hiding from search engines is a yes or a no.' }] : []),
|
|
32
|
+
];
|
|
33
|
+
if (issues.length > 0)
|
|
34
|
+
throw new ValidationError(`This could not be saved: ${issues[0]?.message ?? ''}`, issues);
|
|
35
|
+
return writtenOf(given);
|
|
36
|
+
}
|
|
37
|
+
/** The owner's settings, with what the plugin goes by where one is left empty. */
|
|
38
|
+
async function configOf(cms) {
|
|
39
|
+
const set = await cms.settings.get();
|
|
40
|
+
const key = textOf(set['descriptionField']);
|
|
41
|
+
const longest = set['maxDescription'];
|
|
42
|
+
return {
|
|
43
|
+
titleSuffix: typeof set['titleSuffix'] === 'string' ? set['titleSuffix'] : '',
|
|
44
|
+
descriptionKeys: key === '' ? DESCRIPTION_KEYS : [key],
|
|
45
|
+
maxTitle: MAX_TITLE,
|
|
46
|
+
maxDescription: typeof longest === 'number' && longest > 0 ? longest : MAX_DESCRIPTION,
|
|
47
|
+
requireDescription: set['requireDescription'] === true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** An entry's name for a list: its title, or its slug when it has none yet. */
|
|
51
|
+
function nameOf(type, entry) {
|
|
52
|
+
const fields = liveFields(type.fields);
|
|
53
|
+
const field = fields.find((candidate) => candidate.id === type.titlePath?.[0]) ?? fields.find((candidate) => candidate.type === 'text');
|
|
54
|
+
return textOf(field ? entry.data[field.id] : undefined) || entry.slug;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* SEO: how each entry will read in search results. It shows a preview beside every entry, lists
|
|
58
|
+
* the entries that still need a title or a description, and can hold a publish back until the
|
|
59
|
+
* description is written. Built on the plugin surface alone, as any plugin is.
|
|
60
|
+
*/
|
|
61
|
+
export const seo = definePlugin({
|
|
62
|
+
name: 'seo',
|
|
63
|
+
apiVersion: 1,
|
|
64
|
+
label: { en: 'SEO' },
|
|
65
|
+
description: { en: 'Titles and descriptions for search engines: write them per entry with a live preview, review the whole site, and check before publishing.' },
|
|
66
|
+
version: '1.1.0',
|
|
67
|
+
permissions: ['entry:read'],
|
|
68
|
+
// It comes with the CMS, so it waits for an owner to activate it.
|
|
69
|
+
enabledByDefault: false,
|
|
70
|
+
settings: [
|
|
71
|
+
{
|
|
72
|
+
key: 'titleSuffix',
|
|
73
|
+
type: 'text',
|
|
74
|
+
label: { en: 'Title ending' },
|
|
75
|
+
help: { en: 'Put after the title of every entry\'s page in place of the site\'s own ending, such as " | Lakeshore Realty". Leave empty to keep the site\'s.' },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
key: 'descriptionField',
|
|
79
|
+
type: 'text',
|
|
80
|
+
label: { en: 'Description field' },
|
|
81
|
+
help: { en: 'The key of the field that holds a page\'s description. Leave empty to use "description", "summary", "excerpt" or "intro", whichever a content type has.' },
|
|
82
|
+
},
|
|
83
|
+
{ key: 'maxDescription', type: 'number', label: { en: 'Longest description' }, help: { en: 'In characters. Search engines cut longer ones short. Leave empty for 160.' }, options: { min: 50, integer: true } },
|
|
84
|
+
{ key: 'requireDescription', type: 'boolean', label: { en: 'Require a description before publishing' } },
|
|
85
|
+
],
|
|
86
|
+
// Two functions that stand alone, sent as the text of one module: the editor's part, and the
|
|
87
|
+
// analysis it shares with the server, so both always judge an entry the same way.
|
|
88
|
+
editor: `const analyse = ${analyse.toString()};\nconst editor = ${seoEditor.toString()};\nexport default (api) => editor(api, analyse);\n`,
|
|
89
|
+
setup(cms) {
|
|
90
|
+
cms.checks.add('publish', async ({ entry, type }) => {
|
|
91
|
+
const config = await configOf(cms);
|
|
92
|
+
if (!config.requireDescription)
|
|
93
|
+
return [];
|
|
94
|
+
const fields = liveFields(type.fields);
|
|
95
|
+
const field = config.descriptionKeys.map((key) => fields.find((candidate) => candidate.key === key && candidate.type === 'text')).find((candidate) => candidate !== undefined);
|
|
96
|
+
// A type with no description field has nothing to fill in.
|
|
97
|
+
if (!field || textOf(entry.data[field.key]) !== '')
|
|
98
|
+
return [];
|
|
99
|
+
// One written for search engines counts.
|
|
100
|
+
if (writtenOf(await cms.store.get(`${WRITTEN}${entry.id}`)).description !== undefined)
|
|
101
|
+
return [];
|
|
102
|
+
return [{ path: [field.key], message: 'Write a description before publishing. Search engines show it under the page\'s title.' }];
|
|
103
|
+
});
|
|
104
|
+
cms.routes.add('GET', '/config', () => configOf(cms));
|
|
105
|
+
// What the page of an entry says about itself: what was written for it here, and the
|
|
106
|
+
// owner's title ending. A page that is not an entry's own is left as the template made it.
|
|
107
|
+
cms.pages.head(async ({ entry }, head) => {
|
|
108
|
+
if (!entry)
|
|
109
|
+
return undefined;
|
|
110
|
+
const written = writtenOf(await cms.store.get(`${WRITTEN}${entry.id}`));
|
|
111
|
+
const { titleSuffix } = await configOf(cms);
|
|
112
|
+
const title = written.title ?? head.title;
|
|
113
|
+
return {
|
|
114
|
+
...(written.title !== undefined && { title: written.title }),
|
|
115
|
+
...(titleSuffix !== '' && title !== undefined && { fullTitle: `${title}${titleSuffix}` }),
|
|
116
|
+
...(written.description !== undefined && { description: written.description }),
|
|
117
|
+
...(written.hidden === true && { noindex: true }),
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
cms.routes.add('GET', '/entries/:id', async ({ actor, params }) => {
|
|
121
|
+
// Asked as the person, so what is written for an entry is shown only to someone who may open it.
|
|
122
|
+
const entry = await cms.content.get(actor, params['id'] ?? '');
|
|
123
|
+
return writtenOf(await cms.store.get(`${WRITTEN}${entry.id}`));
|
|
124
|
+
});
|
|
125
|
+
// It shows on the live page at once, with no draft, so it takes someone who may publish.
|
|
126
|
+
cms.routes.add('PUT', '/entries/:id', async ({ actor, params, body }) => {
|
|
127
|
+
const entry = await cms.content.get(actor, params['id'] ?? '');
|
|
128
|
+
const written = checked(body);
|
|
129
|
+
if (Object.keys(written).length === 0)
|
|
130
|
+
await cms.store.remove(`${WRITTEN}${entry.id}`);
|
|
131
|
+
else
|
|
132
|
+
await cms.store.set(`${WRITTEN}${entry.id}`, written);
|
|
133
|
+
await cms.pages.changed();
|
|
134
|
+
return written;
|
|
135
|
+
}, { requires: 'entry:publish' });
|
|
136
|
+
// Read as the person who asked, so nobody is shown an entry they could not open.
|
|
137
|
+
cms.routes.add('GET', '/review', async ({ actor }) => {
|
|
138
|
+
const config = await configOf(cms);
|
|
139
|
+
const items = [];
|
|
140
|
+
const written = await cms.store.list(WRITTEN);
|
|
141
|
+
let checked = 0;
|
|
142
|
+
// Only what has a page of its own is found by a search engine: menus and settings are left out.
|
|
143
|
+
for (const type of (await cms.schema.list()).filter(hasOwnPages)) {
|
|
144
|
+
const { items: entries } = await cms.content.find(actor, { typeId: type.id, order: 'updated', limit: REVIEWED_PER_TYPE });
|
|
145
|
+
for (const entry of entries) {
|
|
146
|
+
checked += 1;
|
|
147
|
+
const { problems } = analyse(type, entry.data, config, writtenOf(written[`${WRITTEN}${entry.id}`]));
|
|
148
|
+
if (problems.length > 0)
|
|
149
|
+
items.push({ id: entry.id, typeKey: type.key, typeLabel: type.label['en'] ?? type.key, name: nameOf(type, entry), status: entry.status, problems });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { items, checked };
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/seo/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAuD,MAAM,0BAA0B,CAAC;AACvJ,OAAO,EAAE,OAAO,EAAqC,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AAEzD,4FAA4F;AAC5F,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,2EAA2E;AAC3E,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACxE,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEnF,0EAA0E;AAC1E,MAAM,OAAO,GAAG,UAAU,CAAC;AAC3B,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,wEAAwE;AACxE,SAAS,SAAS,CAAC,MAAe;IAChC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAA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AE,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;oBACpG,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;wBAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC/K,CAAC;YACH,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address Slack gave for a channel, or why it is not one. Only Slack's own host for incoming
|
|
3
|
+
* webhooks is posted to, so what is saved here can never send a message anywhere else.
|
|
4
|
+
*/
|
|
5
|
+
export declare function slackAddress(text: string): URL;
|
|
6
|
+
/**
|
|
7
|
+
* Slack: posts to a channel when a visitor sends a form and when a new contact is made. An owner
|
|
8
|
+
* saves the channel's incoming webhook address, which is kept as a secret since it is a key. A
|
|
9
|
+
* message says what happened and where; it names the person only if the owner asks for that.
|
|
10
|
+
* One that cannot be posted is tried again for about a day. Built on the plugin surface alone.
|
|
11
|
+
*/
|
|
12
|
+
export declare const slack: import("@velocity-astro/cms-core").PluginDefinition;
|
|
13
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/slack/plugin.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAW9C;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK,qDA2DhB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { definePlugin } from '@velocity-astro/cms-core';
|
|
2
|
+
/** How long Slack has to answer before a try counts as failed. */
|
|
3
|
+
const ANSWER_WITHIN_MS = 5000;
|
|
4
|
+
const POST = 'post';
|
|
5
|
+
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
6
|
+
/** What a person typed, made safe to stand in a Slack message: it can start no link, mention or formatting of its own. */
|
|
7
|
+
const plain = (text) => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/[*_~`]/g, '').slice(0, 200);
|
|
8
|
+
/**
|
|
9
|
+
* The address Slack gave for a channel, or why it is not one. Only Slack's own host for incoming
|
|
10
|
+
* webhooks is posted to, so what is saved here can never send a message anywhere else.
|
|
11
|
+
*/
|
|
12
|
+
export function slackAddress(text) {
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(text.trim());
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
url = undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!url || url.protocol !== 'https:' || url.hostname !== 'hooks.slack.com' || url.port !== '' || url.username !== '' || !url.pathname.startsWith('/services/')) {
|
|
21
|
+
throw new Error('The webhook address is not one of Slack\'s. It starts with https://hooks.slack.com/services/. Save it again under Plugins.');
|
|
22
|
+
}
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Slack: posts to a channel when a visitor sends a form and when a new contact is made. An owner
|
|
27
|
+
* saves the channel's incoming webhook address, which is kept as a secret since it is a key. A
|
|
28
|
+
* message says what happened and where; it names the person only if the owner asks for that.
|
|
29
|
+
* One that cannot be posted is tried again for about a day. Built on the plugin surface alone.
|
|
30
|
+
*/
|
|
31
|
+
export const slack = definePlugin({
|
|
32
|
+
name: 'slack',
|
|
33
|
+
apiVersion: 1,
|
|
34
|
+
label: { en: 'Slack' },
|
|
35
|
+
description: { en: 'Post to a Slack channel when a visitor sends a form or a new contact is made, so your team hears of it at once. Experimental: tested, but not yet tried against the real service.' },
|
|
36
|
+
version: '1.0.0',
|
|
37
|
+
permissions: ['submission:read', 'contact:read'],
|
|
38
|
+
enabledByDefault: false,
|
|
39
|
+
settings: [
|
|
40
|
+
{ key: 'submissions', type: 'boolean', label: { en: 'Post when a form is sent' } },
|
|
41
|
+
{ key: 'contacts', type: 'boolean', label: { en: 'Post when a new contact is made' }, help: { en: 'Tick neither to post both.' } },
|
|
42
|
+
{
|
|
43
|
+
key: 'includePerson',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
label: { en: 'Name the person in the message' },
|
|
46
|
+
help: { en: 'Left off, a message says which form was sent and from which page, and your team opens the CMS to see who. Turned on, the name and email are posted to the channel, where everyone in it can read them.' },
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
secrets: [{ key: 'webhookUrl', label: { en: 'Incoming webhook address' }, help: { en: 'In Slack: add the Incoming Webhooks app to a channel and copy its address. It starts with https://hooks.slack.com/services/.' } }],
|
|
50
|
+
setup(cms) {
|
|
51
|
+
cms.tasks.define(POST, async (payload) => {
|
|
52
|
+
if (!isRecord(payload) || typeof payload['text'] !== 'string')
|
|
53
|
+
throw new Error('This message was kept in a form this version cannot read.');
|
|
54
|
+
const saved = await cms.secrets.get('webhookUrl');
|
|
55
|
+
if (saved === undefined)
|
|
56
|
+
throw new Error('No webhook address is saved. Save one under Plugins, then try again.');
|
|
57
|
+
const url = slackAddress(saved);
|
|
58
|
+
let answer;
|
|
59
|
+
try {
|
|
60
|
+
answer = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', 'user-agent': 'Velocity-CMS-Slack/1' }, body: JSON.stringify({ text: payload['text'] }), redirect: 'manual', signal: AbortSignal.timeout(ANSWER_WITHIN_MS) });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`Slack could not be reached within ${ANSWER_WITHIN_MS / 1000} seconds.`);
|
|
64
|
+
}
|
|
65
|
+
if (answer.status === 403 || answer.status === 404 || answer.status === 410)
|
|
66
|
+
throw new Error('Slack no longer takes this webhook address. Make a new one in Slack and save it under Plugins.');
|
|
67
|
+
if (!answer.ok)
|
|
68
|
+
throw new Error(`Slack answered ${answer.status}.`);
|
|
69
|
+
});
|
|
70
|
+
const wants = async (what) => {
|
|
71
|
+
const settings = await cms.settings.get();
|
|
72
|
+
return { asked: settings[what] === true || (settings['submissions'] !== true && settings['contacts'] !== true), person: settings['includePerson'] === true };
|
|
73
|
+
};
|
|
74
|
+
// What looks like spam is kept in the inbox and told to nobody else.
|
|
75
|
+
cms.events.on('submission.received', async ({ submission, form }) => {
|
|
76
|
+
if (submission.status === 'spam')
|
|
77
|
+
return;
|
|
78
|
+
const { asked, person } = await wants('submissions');
|
|
79
|
+
if (!asked)
|
|
80
|
+
return;
|
|
81
|
+
const name = plain(form.label['en'] ?? Object.values(form.label)[0] ?? form.key);
|
|
82
|
+
const from = submission.page === undefined ? '' : ` from ${plain(submission.page)}`;
|
|
83
|
+
const who = person && submission.email !== undefined ? ` by ${plain(submission.email)}` : '';
|
|
84
|
+
await cms.tasks.add(POST, { text: `:incoming_envelope: *${name}* was sent${from}${who}.` }, { label: `A form sent, to Slack` });
|
|
85
|
+
});
|
|
86
|
+
cms.events.on('contact.saved', async ({ contact, imported }) => {
|
|
87
|
+
// Only the first save is news: later ones are the team's own changes, and a file of contacts is not news line by line.
|
|
88
|
+
if (contact.revision !== 1 || imported === true)
|
|
89
|
+
return;
|
|
90
|
+
const { asked, person } = await wants('contacts');
|
|
91
|
+
if (!asked)
|
|
92
|
+
return;
|
|
93
|
+
const who = person ? `: ${plain(contact.name ?? contact.email)}${contact.name !== undefined ? ` (${plain(contact.email)})` : ''}` : '';
|
|
94
|
+
await cms.tasks.add(POST, { text: `:bust_in_silhouette: A new contact was added${who}.` }, { label: 'A new contact, to Slack' });
|
|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AAE,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;YAC7D,uHAAuH;YACvH,IAAI,OAAO,CAAC,QAAQ,KAAK,CAAC,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO;YACxD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,CAAC,KAAK;gBAAE,OAAO;YACnB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvI,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,+CAA+C,GAAG,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC,CAAC;QACnI,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address as it may be sent to, or why it may not. Only `https`, and never this machine or a
|
|
3
|
+
* bare number: an address typed into settings must not become a way to reach what sits beside
|
|
4
|
+
* the site.
|
|
5
|
+
*/
|
|
6
|
+
export declare function deliveryAddress(text: string): URL;
|
|
7
|
+
/**
|
|
8
|
+
* Webhooks: tells other services what happens on the site, as it happens. Each address an owner
|
|
9
|
+
* lists is sent a small JSON message when a form is submitted, a contact or a deal changes, or a
|
|
10
|
+
* page is published. A message that cannot be delivered is tried again for about a day, and the
|
|
11
|
+
* owner sees each one under Plugins. Built on the plugin surface alone.
|
|
12
|
+
*/
|
|
13
|
+
export declare const webhooks: import("@velocity-astro/cms-core").PluginDefinition;
|
|
14
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/webhooks/plugin.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAejD;AAyBD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,qDA+FnB,CAAC"}
|