inlaycms 0.6.0 → 0.7.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.
Files changed (36) hide show
  1. package/assets/admin/admin.js +1 -1
  2. package/dist/adapters/admin/screens/media.d.ts +4 -1
  3. package/dist/adapters/admin/screens/media.js +22 -2
  4. package/dist/adapters/admin/screens/redirects.js +3 -1
  5. package/dist/adapters/cli/main.js +9 -1
  6. package/dist/adapters/mcp/tools/read.d.ts +1 -1
  7. package/dist/adapters/mcp/tools/read.js +44 -1
  8. package/dist/adapters/mcp/tools/write.js +76 -5
  9. package/dist/adapters/site/plugin.d.ts +2 -0
  10. package/dist/adapters/site/plugin.js +10 -1
  11. package/dist/adapters/site/public.d.ts +9 -1
  12. package/dist/adapters/site/public.js +48 -30
  13. package/dist/core/content/find-text.d.ts +31 -0
  14. package/dist/core/content/find-text.js +124 -0
  15. package/dist/core/content/search.js +1 -14
  16. package/dist/core/content/text-match.d.ts +14 -0
  17. package/dist/core/content/text-match.js +99 -0
  18. package/dist/core/content/text-replace.d.ts +14 -0
  19. package/dist/core/content/text-replace.js +100 -0
  20. package/dist/core/core.d.ts +7 -0
  21. package/dist/core/core.js +2 -0
  22. package/dist/core/messages/en.d.ts +33 -2
  23. package/dist/core/messages/en.js +33 -2
  24. package/dist/core/release/pack.js +4 -0
  25. package/dist/core/release/public-files.d.ts +14 -0
  26. package/dist/core/release/public-files.js +43 -0
  27. package/dist/core/release/window.d.ts +2 -0
  28. package/dist/core/release/window.js +6 -0
  29. package/dist/core/report.d.ts +1 -1
  30. package/dist/core/richtext/runs.d.ts +12 -0
  31. package/dist/core/richtext/runs.js +31 -0
  32. package/dist/core/version.d.ts +2 -0
  33. package/dist/core/version.js +2 -0
  34. package/dist/host/app.d.ts +6 -0
  35. package/dist/host/app.js +3 -0
  36. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ export type ReplaceKind = 'text' | 'textarea' | 'richText' | 'inlineText' | 'link';
2
+ type ReplaceFailure = {
3
+ ok: false;
4
+ reason: 'notFound' | 'occurrence' | 'noOccurrences' | 'spansFormatting';
5
+ count: number;
6
+ };
7
+ export type ReplaceResult = {
8
+ ok: true;
9
+ value: unknown;
10
+ count: number;
11
+ } | ReplaceFailure;
12
+ /** Swaps a phrase, exactly as written, inside one field's stored value. Never mutates `value`. */
13
+ export declare function replaceText(kind: ReplaceKind, value: unknown, find: string, replace: string, occurrences?: number[]): ReplaceResult;
14
+ export {};
@@ -0,0 +1,100 @@
1
+ import { isRecord } from '../fields/zod-internals.js';
2
+ import { textRuns } from '../richtext/runs.js';
3
+ import { findPhrase } from './text-match.js';
4
+ /**
5
+ * The occurrences of `find` in `text`: the hits find_text reports for it that are written exactly as `find`,
6
+ * so both number the same occurrences.
7
+ */
8
+ const occurrencesOf = (text, find) => findPhrase(text, find, 'loose').filter((hit) => hit.text === find);
9
+ /** The numbers picked by the caller, or null for "all"; a failure when there are none or one is out of range. */
10
+ function selection(occurrences, count) {
11
+ if (occurrences === undefined)
12
+ return null;
13
+ if (occurrences.length === 0)
14
+ return { ok: false, reason: 'noOccurrences', count };
15
+ for (const n of occurrences)
16
+ if (!Number.isInteger(n) || n < 1 || n > count)
17
+ return { ok: false, reason: 'occurrence', count };
18
+ return new Set(occurrences);
19
+ }
20
+ function replaceInString(text, find, replace, occurrences) {
21
+ const hits = occurrencesOf(text, find);
22
+ if (hits.length === 0)
23
+ return { ok: false, reason: 'notFound', count: 0 };
24
+ const picked = selection(occurrences, hits.length);
25
+ if (picked !== null && !(picked instanceof Set))
26
+ return picked;
27
+ let out = '';
28
+ let at = 0;
29
+ let count = 0;
30
+ hits.forEach((hit, i) => {
31
+ if (picked && !picked.has(i + 1))
32
+ return;
33
+ out += text.slice(at, hit.start) + replace;
34
+ at = hit.end;
35
+ count++;
36
+ });
37
+ out += text.slice(at);
38
+ return { ok: true, value: out, count };
39
+ }
40
+ function pruneEmptyText(node) {
41
+ if (!Array.isArray(node.content))
42
+ return;
43
+ const kept = node.content.filter((child) => !(isRecord(child) && child.type === 'text' && child.text === ''));
44
+ for (const child of kept)
45
+ if (isRecord(child))
46
+ pruneEmptyText(child);
47
+ if (kept.length === 0)
48
+ delete node.content;
49
+ else
50
+ node.content = kept;
51
+ }
52
+ function replaceInRichText(value, find, replace, occurrences) {
53
+ if (!isRecord(value) || value.type !== 'doc' || !Array.isArray(value.content)) {
54
+ return { ok: false, reason: 'notFound', count: 0 };
55
+ }
56
+ const doc = structuredClone(value);
57
+ const found = [];
58
+ let total = 0;
59
+ for (const run of textRuns(doc)) {
60
+ for (const hit of occurrencesOf(run.text, find)) {
61
+ total++;
62
+ const piece = run.pieces.find((p) => hit.start >= p.start && hit.end <= p.end);
63
+ found.push({
64
+ piece: piece ?? run.pieces[0],
65
+ start: piece ? hit.start - piece.start : 0,
66
+ end: piece ? hit.end - piece.start : 0,
67
+ spans: !piece,
68
+ number: total,
69
+ });
70
+ }
71
+ }
72
+ if (total === 0)
73
+ return { ok: false, reason: 'notFound', count: 0 };
74
+ const picked = selection(occurrences, total);
75
+ if (picked !== null && !(picked instanceof Set))
76
+ return picked;
77
+ const chosen = found.filter((f) => !picked || picked.has(f.number));
78
+ if (chosen.some((f) => f.spans))
79
+ return { ok: false, reason: 'spansFormatting', count: total };
80
+ for (const f of [...chosen].reverse()) {
81
+ const node = f.piece.node;
82
+ node.text = node.text.slice(0, f.start) + replace + node.text.slice(f.end);
83
+ }
84
+ pruneEmptyText(doc);
85
+ return { ok: true, value: doc, count: chosen.length };
86
+ }
87
+ /** Swaps a phrase, exactly as written, inside one field's stored value. Never mutates `value`. */
88
+ export function replaceText(kind, value, find, replace, occurrences) {
89
+ if (kind === 'richText' || kind === 'inlineText')
90
+ return replaceInRichText(value, find, replace, occurrences);
91
+ if (kind === 'link') {
92
+ if (!isRecord(value) || typeof value.text !== 'string')
93
+ return { ok: false, reason: 'notFound', count: 0 };
94
+ const result = replaceInString(value.text, find, replace, occurrences);
95
+ return result.ok ? { ...result, value: { ...value, text: result.value } } : result;
96
+ }
97
+ if (typeof value !== 'string')
98
+ return { ok: false, reason: 'notFound', count: 0 };
99
+ return replaceInString(value, find, replace, occurrences);
100
+ }
@@ -1,4 +1,5 @@
1
1
  import type { Kysely } from 'kysely';
2
+ import { type FindTextResult } from './content/find-text.js';
2
3
  import { type PublishResult } from './content/publish.js';
3
4
  import { type ShippedItem, type ShippedReport } from './content/shipped.js';
4
5
  import { type PatchOp } from './content/patch.js';
@@ -53,6 +54,12 @@ export interface Core {
53
54
  }): Promise<Array<DocumentSummary & {
54
55
  snippet: string;
55
56
  }>>;
57
+ findText(text: string, opts?: {
58
+ type?: string;
59
+ locale?: string;
60
+ limit?: number;
61
+ offset?: number;
62
+ }): Promise<FindTextResult>;
56
63
  publish(documentIds: string[], ctx: Ctx, opts?: {
57
64
  message?: string;
58
65
  expect?: Record<string, number>;
package/dist/core/core.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { findSingleton, findTranslation, getDocument, listEntries } from './content/read.js';
2
+ import { findText } from './content/find-text.js';
2
3
  import { findEntry, searchEntries } from './content/search.js';
3
4
  import { recentActivity } from './content/activity.js';
4
5
  import { withTransaction } from './content/dry-run.js';
@@ -85,6 +86,7 @@ export function createCore(opts) {
85
86
  patchDraft: (id, input, ctx) => patchDraft(deps, id, input, ctx),
86
87
  findEntry: (type, slug, locale) => findEntry(deps, type, slug, locale),
87
88
  searchEntries: (type, query, o) => searchEntries(deps, type, query, o),
89
+ findText: (text, o) => findText(deps, text, o),
88
90
  publish: live((ids, ctx, o) => publish(deps, ids, ctx, o), (r, ...args) => published(r) && !args[2]?.dryRun),
89
91
  unpublish: live((ids, ctx, o) => unpublish(deps, ids, ctx, o), (r, ...args) => published(r) && !args[2]?.dryRun),
90
92
  describeChanges: (ids) => describeChanges(deps, ids),
@@ -290,6 +290,10 @@ export declare const en: {
290
290
  readonly 'error.packImport': "{file} imports {specifier}, which a release can't include. Site code imports Inlay from inlaycms/site (and the JSX runtime), and may use packages that can be bundled with it, but not Node's own modules or the rest of inlaycms. This check catches mistakes; what makes a release trusted is its signature.";
291
291
  readonly 'error.packForbidden': "{file} uses {what}, which a release can't include. Site code can't reach the server's process, load code by a computed name or run code from text. This check catches mistakes; what makes a release trusted is its signature.";
292
292
  readonly 'error.packBundle': "The site code couldn't be bundled into a release: {problem}";
293
+ readonly 'error.publicReserved': 'The file public/{file} would also be served at {path}, which belongs to Inlay itself. Rename or move the file.';
294
+ readonly 'error.publicRoute': 'The file public/{file} would also be served at {path}, where the site already has a route. Rename the file or change the route.';
295
+ readonly 'error.publicRedirect': 'The file public/{file} would also be served at {path}, where the site already has a redirect. Rename the file or change the redirect.';
296
+ readonly 'error.publicPage': "The file public/{file} would also be served at {path}, which is already the address of a page. Rename the file or change the page's path.";
293
297
  readonly 'error.packFile': 'The shipped content names the file {path}, but there is no file there.';
294
298
  readonly 'error.markdownImageReference': "{file}, line {line}: this image is written as a reference ([alt][name]), which Inlay can't follow in a Markdown file. Write the image inline instead, such as ![A chart](images/chart.png).";
295
299
  readonly 'error.markdownImageUnplaced': "{file}, line {line}: Inlay couldn't work out where this image's file is. Put the image on a line of its own, written simply, such as ![A chart](images/chart.png).";
@@ -604,6 +608,8 @@ export declare const en: {
604
608
  readonly 'admin.search.recent': 'Recently changed';
605
609
  readonly 'admin.search.seeAll': 'See all {count} in {label}';
606
610
  readonly 'admin.search.results': 'Search results';
611
+ readonly 'admin.copy': 'Copy';
612
+ readonly 'admin.copied': 'Copied';
607
613
  readonly 'admin.breadcrumbs': 'You are here';
608
614
  readonly 'admin.time.utc': '{time} UTC';
609
615
  readonly 'admin.forbidden.title': "You can't open this page";
@@ -1205,6 +1211,8 @@ export declare const en: {
1205
1211
  readonly 'admin.media.dimensionsValue': '{width} x {height}';
1206
1212
  readonly 'admin.media.uploadedBy': 'Uploaded by';
1207
1213
  readonly 'admin.media.uploadedByValue': '{name}, {time}';
1214
+ readonly 'admin.media.address': 'Address';
1215
+ readonly 'admin.media.addressHint': 'Link to the file with this address. Uploading a new version gives it a new address.';
1208
1216
  readonly 'admin.media.download': 'Download the file';
1209
1217
  readonly 'admin.media.altHeading': 'Description of the image';
1210
1218
  readonly 'admin.media.alt': 'Default description (alt text)';
@@ -1216,6 +1224,11 @@ export declare const en: {
1216
1224
  readonly 'admin.media.usage.draft': 'in the draft';
1217
1225
  readonly 'admin.media.usage.published': 'on the live site';
1218
1226
  readonly 'admin.media.usage.both': 'in the draft and on the live site';
1227
+ readonly 'admin.media.redirectsHeading': 'Friendly addresses';
1228
+ readonly 'admin.media.redirectsNone': 'No friendly addresses point to this file yet.';
1229
+ readonly 'admin.media.redirectsHint': "A friendly address like /privacy-policy.pdf sends visitors to this file. It's added as a temporary redirect, so you can point it at a new version later without browsers holding on to the old file.";
1230
+ readonly 'admin.media.redirectsAdd': 'Add a friendly address';
1231
+ readonly 'admin.media.delete.redirects': 'These addresses point to this file and will stop working:';
1219
1232
  readonly 'admin.media.delete': 'Delete';
1220
1233
  readonly 'admin.media.delete.title': 'Delete {filename}?';
1221
1234
  readonly 'admin.media.delete.confirm': 'This removes "{filename}" from the media library. This cannot be undone.';
@@ -1288,6 +1301,8 @@ export declare const en: {
1288
1301
  readonly 'mcp.tool.get_document.description': 'Reads one page, entry or global in one language: its content (in the form update_document and create_entry accept), its ids, its address on the live site (null until it is published there) and a preview link. Give its id, or its type (and slug, for an entry of a collection whose entries have pages).';
1289
1302
  readonly 'mcp.tool.search_entries.title': 'Find entries';
1290
1303
  readonly 'mcp.tool.search_entries.description': 'Finds entries of a collection whose title or text contains every word of the query, ignoring case and accents. Leave out the query to list the newest entries.';
1304
+ readonly 'mcp.tool.find_text.title': 'Find text across the site';
1305
+ readonly 'mcp.tool.find_text.description': 'Finds a word or phrase in every page, global and entry, in every language unless you give a locale. It ignores case and accents and matches whole words, so "Acme" is found in "Acme\'s" but not in "Acmeville". It looks in text, rich text and button or link labels, not in link addresses, image descriptions or pages designed in code. For each page it returns its revisionId and, for each field, the path, the exact text as written and numbered occurrences with a snippet around each. To change them, use update_document with { path, find: <text>, replace, occurrences? }, one page or entry per call. Returns 20 pages at a time by default; use offset to see more.';
1291
1306
  readonly 'mcp.tool.list_gaps.title': 'List missing content';
1292
1307
  readonly 'mcp.tool.list_gaps.description': "Lists the pages and entries whose published version is missing something the site now requires, such as a required field added after they were published, with each missing field, and how many there are in all. Visitors still see them as they are. Fill in the fields with update_document, then publish. Give a type to list only that type. Returns 50 at a time by default; use offset to see the next ones.";
1293
1308
  readonly 'mcp.param.type': 'The content type, as named in describe_site.';
@@ -1301,6 +1316,13 @@ export declare const en: {
1301
1316
  readonly 'mcp.param.state': '"draft" (the default) reads the latest version, with unpublished changes. "published" reads what visitors see.';
1302
1317
  readonly 'mcp.param.collection': 'The collection, as named in describe_site.';
1303
1318
  readonly 'mcp.param.query': 'The words to look for.';
1319
+ readonly 'mcp.param.findText': 'The word or phrase to look for.';
1320
+ readonly 'mcp.param.findType': 'Only look in this content type, as named in describe_site.';
1321
+ readonly 'mcp.param.findLocale': 'Only look in this language, such as "en". Defaults to every language.';
1322
+ readonly 'mcp.param.findLimit': 'How many pages and entries to return, at most 100. Defaults to 20.';
1323
+ readonly 'mcp.param.findOffset': 'How many pages and entries to skip, to see the next ones. Defaults to 0.';
1324
+ readonly 'mcp.findText.blank': 'Give the words to look for.';
1325
+ readonly 'mcp.findText.designedInCode': "These pages are designed in code. Their words are in the site's template, so only the site's developer can change them.";
1304
1326
  readonly 'mcp.param.limit': 'How many entries to return, at most 50. Defaults to 10.';
1305
1327
  readonly 'mcp.conflict': 'Someone else changed "{title}" since you read it. Read it again with get_document and redo your change.';
1306
1328
  readonly 'mcp.useGroupId': '"{id}" is the document id of one language version, not the groupId that links, references and redirects need. Use "{groupId}" instead.';
@@ -1308,9 +1330,15 @@ export declare const en: {
1308
1330
  readonly 'mcp.change.both': 'This change has both a value and remove. Give a value to set the field, or remove: true to remove it, not both.';
1309
1331
  readonly 'mcp.change.required': "{field} is required, so it can't be removed. Give it a new value instead.";
1310
1332
  readonly 'mcp.change.neither': 'This change has no value. Give a value to set the field, or remove: true to remove it.';
1333
+ readonly 'mcp.change.replaceShape': 'To replace text, give find and replace (replace can be "" to delete it), and optionally occurrences, but no value or remove.';
1334
+ readonly 'mcp.change.notText': 'Text can only be replaced inside a text or rich text field, or a button or link label (the path ending in .text). Set this one with value instead.';
1335
+ readonly 'mcp.change.notFound': '{field} doesn\'t contain "{find}" written exactly like that. Look again with find_text or get_document.';
1336
+ readonly 'mcp.change.occurrence': '{field} contains "{find}" only {count} {count|time|times}. Number occurrences from 1, as find_text lists them, or leave occurrences out to change them all.';
1337
+ readonly 'mcp.change.noOccurrences': 'occurrences is empty, so nothing in {field} would change. List which occurrences of "{find}" to change, numbered from 1 as find_text lists them, or leave occurrences out to change them all.';
1338
+ readonly 'mcp.change.spansFormatting': 'In {field}, part of "{find}" is formatted differently or is a link, so it can\'t be replaced. Change the whole field with value instead, or leave that occurrence out with occurrences.';
1311
1339
  readonly 'mcp.tool.update_document.title': 'Change a page or entry';
1312
1340
  readonly 'mcp.designedInCode': "This page is designed in code: its words and layout are written into the site's template, so it has nothing to edit. Tell the person to ask their developer to change it.";
1313
- readonly 'mcp.tool.update_document.description': "Changes fields of one page, entry or global in one language, saved as a draft that visitors don't see until it is published. Give its document id and the revisionId you got from get_document as baseRevisionId. Each change sets the value at a dotted path (such as slots.hero.data.headline or fields.faq.0.question), in the same form get_document returns, or removes an optional field with remove: true. If anything is wrong, nothing is saved. Returns the new revisionId, the changes in plain words, and a preview link to give the user.";
1341
+ readonly 'mcp.tool.update_document.description': "Changes fields of one page, entry or global in one language, saved as a draft that visitors don't see until it is published. Give its document id and the revisionId you got from get_document as baseRevisionId. Each change sets the value at a dotted path (such as slots.hero.data.headline or fields.faq.0.question), in the same form get_document returns, or removes an optional field with remove: true. A change of { path, find, replace, occurrences? } changes just that text inside a field (text, rich text or a button label) and keeps the rest, its links and formatting as they are. If anything is wrong, nothing is saved. Returns the new revisionId, the changes in plain words, and a preview link to give the user.";
1314
1342
  readonly 'mcp.tool.create_entry.title': 'Add an entry';
1315
1343
  readonly 'mcp.tool.create_entry.description': "Adds a new entry to a collection, as an unpublished draft. Give the collection's name from describe_site and the content in the form get_document returns (read describe_type first). Leave out the slug to make one from the title. Entries are created in the main language; add other languages with create_translation. Returns the new entry's id and groupId, and a preview link to give the user.";
1316
1344
  readonly 'mcp.tool.create_translation.title': 'Translate a page or entry';
@@ -1322,10 +1350,13 @@ export declare const en: {
1322
1350
  readonly 'mcp.tool.get_preview_link.title': 'Get a preview link';
1323
1351
  readonly 'mcp.tool.get_preview_link.description': "Gives a link that shows the site with every unpublished change, for the user to check. Give a document id to open that page, or leave it out to open the home page. Globals and entries without a page open the home page.";
1324
1352
  readonly 'mcp.param.baseRevisionId': 'The revisionId of the version your changes are based on, from get_document or your last update_document. If someone changed the document since then, nothing is saved.';
1325
- readonly 'mcp.param.changes': 'The changes to make, in order (1 to 100). Each one has a path and either a value or remove: true.';
1353
+ readonly 'mcp.param.changes': 'The changes to make, in order (1 to 100). Each one has a path and either a value, remove: true, or find and replace.';
1326
1354
  readonly 'mcp.param.changePath': 'Where to make the change: names and list positions joined by dots, such as slots.hero.data.headline or fields.faq.0.question. "fields" or "slots.<slot>" replaces all of it.';
1327
1355
  readonly 'mcp.param.changeValue': 'The new value, in the form get_document returns. Rich text is Markdown.';
1328
1356
  readonly 'mcp.param.changeRemove': 'true to remove the value at the path. Only optional fields can be removed.';
1357
+ readonly 'mcp.param.changeFind': 'The exact text to replace in the field at the path, written as find_text reported it (same capitals and accents). It matches whole words only.';
1358
+ readonly 'mcp.param.changeReplace': 'The new text for find. It is plain text, not Markdown. "" deletes it.';
1359
+ readonly 'mcp.param.changeOccurrences': 'Which occurrences of find to change, numbered from 1 as find_text lists them. Leave it out to change them all.';
1329
1360
  readonly 'mcp.param.message': 'A short note about the change, kept in the history.';
1330
1361
  readonly 'mcp.param.content': 'The content of the entry, in the form get_document returns: { slug?, path?, fields, slots }. A slot of { enabled: false } is switched off.';
1331
1362
  readonly 'mcp.param.translateId': 'The document id of the page, entry or global, in any language it already has.';
@@ -290,6 +290,10 @@ export const en = {
290
290
  'error.packImport': "{file} imports {specifier}, which a release can't include. Site code imports Inlay from inlaycms/site (and the JSX runtime), and may use packages that can be bundled with it, but not Node's own modules or the rest of inlaycms. This check catches mistakes; what makes a release trusted is its signature.",
291
291
  'error.packForbidden': "{file} uses {what}, which a release can't include. Site code can't reach the server's process, load code by a computed name or run code from text. This check catches mistakes; what makes a release trusted is its signature.",
292
292
  'error.packBundle': "The site code couldn't be bundled into a release: {problem}",
293
+ 'error.publicReserved': 'The file public/{file} would also be served at {path}, which belongs to Inlay itself. Rename or move the file.',
294
+ 'error.publicRoute': 'The file public/{file} would also be served at {path}, where the site already has a route. Rename the file or change the route.',
295
+ 'error.publicRedirect': 'The file public/{file} would also be served at {path}, where the site already has a redirect. Rename the file or change the redirect.',
296
+ 'error.publicPage': "The file public/{file} would also be served at {path}, which is already the address of a page. Rename the file or change the page's path.",
293
297
  'error.packFile': 'The shipped content names the file {path}, but there is no file there.',
294
298
  'error.markdownImageReference': "{file}, line {line}: this image is written as a reference ([alt][name]), which Inlay can't follow in a Markdown file. Write the image inline instead, such as ![A chart](images/chart.png).",
295
299
  'error.markdownImageUnplaced': "{file}, line {line}: Inlay couldn't work out where this image's file is. Put the image on a line of its own, written simply, such as ![A chart](images/chart.png).",
@@ -604,6 +608,8 @@ export const en = {
604
608
  'admin.search.recent': 'Recently changed',
605
609
  'admin.search.seeAll': 'See all {count} in {label}',
606
610
  'admin.search.results': 'Search results',
611
+ 'admin.copy': 'Copy',
612
+ 'admin.copied': 'Copied',
607
613
  'admin.breadcrumbs': 'You are here',
608
614
  'admin.time.utc': '{time} UTC',
609
615
  'admin.forbidden.title': "You can't open this page",
@@ -1205,6 +1211,8 @@ export const en = {
1205
1211
  'admin.media.dimensionsValue': '{width} x {height}',
1206
1212
  'admin.media.uploadedBy': 'Uploaded by',
1207
1213
  'admin.media.uploadedByValue': '{name}, {time}',
1214
+ 'admin.media.address': 'Address',
1215
+ 'admin.media.addressHint': 'Link to the file with this address. Uploading a new version gives it a new address.',
1208
1216
  'admin.media.download': 'Download the file',
1209
1217
  'admin.media.altHeading': 'Description of the image',
1210
1218
  'admin.media.alt': 'Default description (alt text)',
@@ -1216,6 +1224,11 @@ export const en = {
1216
1224
  'admin.media.usage.draft': 'in the draft',
1217
1225
  'admin.media.usage.published': 'on the live site',
1218
1226
  'admin.media.usage.both': 'in the draft and on the live site',
1227
+ 'admin.media.redirectsHeading': 'Friendly addresses',
1228
+ 'admin.media.redirectsNone': 'No friendly addresses point to this file yet.',
1229
+ 'admin.media.redirectsHint': "A friendly address like /privacy-policy.pdf sends visitors to this file. It's added as a temporary redirect, so you can point it at a new version later without browsers holding on to the old file.",
1230
+ 'admin.media.redirectsAdd': 'Add a friendly address',
1231
+ 'admin.media.delete.redirects': 'These addresses point to this file and will stop working:',
1219
1232
  'admin.media.delete': 'Delete',
1220
1233
  'admin.media.delete.title': 'Delete {filename}?',
1221
1234
  'admin.media.delete.confirm': 'This removes "{filename}" from the media library. This cannot be undone.',
@@ -1297,6 +1310,8 @@ export const en = {
1297
1310
  'mcp.tool.get_document.description': 'Reads one page, entry or global in one language: its content (in the form update_document and create_entry accept), its ids, its address on the live site (null until it is published there) and a preview link. Give its id, or its type (and slug, for an entry of a collection whose entries have pages).',
1298
1311
  'mcp.tool.search_entries.title': 'Find entries',
1299
1312
  'mcp.tool.search_entries.description': 'Finds entries of a collection whose title or text contains every word of the query, ignoring case and accents. Leave out the query to list the newest entries.',
1313
+ 'mcp.tool.find_text.title': 'Find text across the site',
1314
+ 'mcp.tool.find_text.description': 'Finds a word or phrase in every page, global and entry, in every language unless you give a locale. It ignores case and accents and matches whole words, so "Acme" is found in "Acme\'s" but not in "Acmeville". It looks in text, rich text and button or link labels, not in link addresses, image descriptions or pages designed in code. For each page it returns its revisionId and, for each field, the path, the exact text as written and numbered occurrences with a snippet around each. To change them, use update_document with { path, find: <text>, replace, occurrences? }, one page or entry per call. Returns 20 pages at a time by default; use offset to see more.',
1300
1315
  'mcp.tool.list_gaps.title': 'List missing content',
1301
1316
  'mcp.tool.list_gaps.description': "Lists the pages and entries whose published version is missing something the site now requires, such as a required field added after they were published, with each missing field, and how many there are in all. Visitors still see them as they are. Fill in the fields with update_document, then publish. Give a type to list only that type. Returns 50 at a time by default; use offset to see the next ones.",
1302
1317
  'mcp.param.type': 'The content type, as named in describe_site.',
@@ -1310,6 +1325,13 @@ export const en = {
1310
1325
  'mcp.param.state': '"draft" (the default) reads the latest version, with unpublished changes. "published" reads what visitors see.',
1311
1326
  'mcp.param.collection': 'The collection, as named in describe_site.',
1312
1327
  'mcp.param.query': 'The words to look for.',
1328
+ 'mcp.param.findText': 'The word or phrase to look for.',
1329
+ 'mcp.param.findType': 'Only look in this content type, as named in describe_site.',
1330
+ 'mcp.param.findLocale': 'Only look in this language, such as "en". Defaults to every language.',
1331
+ 'mcp.param.findLimit': 'How many pages and entries to return, at most 100. Defaults to 20.',
1332
+ 'mcp.param.findOffset': 'How many pages and entries to skip, to see the next ones. Defaults to 0.',
1333
+ 'mcp.findText.blank': 'Give the words to look for.',
1334
+ 'mcp.findText.designedInCode': "These pages are designed in code. Their words are in the site's template, so only the site's developer can change them.",
1313
1335
  'mcp.param.limit': 'How many entries to return, at most 50. Defaults to 10.',
1314
1336
  'mcp.conflict': 'Someone else changed "{title}" since you read it. Read it again with get_document and redo your change.',
1315
1337
  'mcp.useGroupId': '"{id}" is the document id of one language version, not the groupId that links, references and redirects need. Use "{groupId}" instead.',
@@ -1317,9 +1339,15 @@ export const en = {
1317
1339
  'mcp.change.both': 'This change has both a value and remove. Give a value to set the field, or remove: true to remove it, not both.',
1318
1340
  'mcp.change.required': "{field} is required, so it can't be removed. Give it a new value instead.",
1319
1341
  'mcp.change.neither': 'This change has no value. Give a value to set the field, or remove: true to remove it.',
1342
+ 'mcp.change.replaceShape': 'To replace text, give find and replace (replace can be "" to delete it), and optionally occurrences, but no value or remove.',
1343
+ 'mcp.change.notText': 'Text can only be replaced inside a text or rich text field, or a button or link label (the path ending in .text). Set this one with value instead.',
1344
+ 'mcp.change.notFound': '{field} doesn\'t contain "{find}" written exactly like that. Look again with find_text or get_document.',
1345
+ 'mcp.change.occurrence': '{field} contains "{find}" only {count} {count|time|times}. Number occurrences from 1, as find_text lists them, or leave occurrences out to change them all.',
1346
+ 'mcp.change.noOccurrences': 'occurrences is empty, so nothing in {field} would change. List which occurrences of "{find}" to change, numbered from 1 as find_text lists them, or leave occurrences out to change them all.',
1347
+ 'mcp.change.spansFormatting': 'In {field}, part of "{find}" is formatted differently or is a link, so it can\'t be replaced. Change the whole field with value instead, or leave that occurrence out with occurrences.',
1320
1348
  'mcp.tool.update_document.title': 'Change a page or entry',
1321
1349
  'mcp.designedInCode': "This page is designed in code: its words and layout are written into the site's template, so it has nothing to edit. Tell the person to ask their developer to change it.",
1322
- 'mcp.tool.update_document.description': "Changes fields of one page, entry or global in one language, saved as a draft that visitors don't see until it is published. Give its document id and the revisionId you got from get_document as baseRevisionId. Each change sets the value at a dotted path (such as slots.hero.data.headline or fields.faq.0.question), in the same form get_document returns, or removes an optional field with remove: true. If anything is wrong, nothing is saved. Returns the new revisionId, the changes in plain words, and a preview link to give the user.",
1350
+ 'mcp.tool.update_document.description': "Changes fields of one page, entry or global in one language, saved as a draft that visitors don't see until it is published. Give its document id and the revisionId you got from get_document as baseRevisionId. Each change sets the value at a dotted path (such as slots.hero.data.headline or fields.faq.0.question), in the same form get_document returns, or removes an optional field with remove: true. A change of { path, find, replace, occurrences? } changes just that text inside a field (text, rich text or a button label) and keeps the rest, its links and formatting as they are. If anything is wrong, nothing is saved. Returns the new revisionId, the changes in plain words, and a preview link to give the user.",
1323
1351
  'mcp.tool.create_entry.title': 'Add an entry',
1324
1352
  'mcp.tool.create_entry.description': "Adds a new entry to a collection, as an unpublished draft. Give the collection's name from describe_site and the content in the form get_document returns (read describe_type first). Leave out the slug to make one from the title. Entries are created in the main language; add other languages with create_translation. Returns the new entry's id and groupId, and a preview link to give the user.",
1325
1353
  'mcp.tool.create_translation.title': 'Translate a page or entry',
@@ -1331,10 +1359,13 @@ export const en = {
1331
1359
  'mcp.tool.get_preview_link.title': 'Get a preview link',
1332
1360
  'mcp.tool.get_preview_link.description': "Gives a link that shows the site with every unpublished change, for the user to check. Give a document id to open that page, or leave it out to open the home page. Globals and entries without a page open the home page.",
1333
1361
  'mcp.param.baseRevisionId': 'The revisionId of the version your changes are based on, from get_document or your last update_document. If someone changed the document since then, nothing is saved.',
1334
- 'mcp.param.changes': 'The changes to make, in order (1 to 100). Each one has a path and either a value or remove: true.',
1362
+ 'mcp.param.changes': 'The changes to make, in order (1 to 100). Each one has a path and either a value, remove: true, or find and replace.',
1335
1363
  'mcp.param.changePath': 'Where to make the change: names and list positions joined by dots, such as slots.hero.data.headline or fields.faq.0.question. "fields" or "slots.<slot>" replaces all of it.',
1336
1364
  'mcp.param.changeValue': 'The new value, in the form get_document returns. Rich text is Markdown.',
1337
1365
  'mcp.param.changeRemove': 'true to remove the value at the path. Only optional fields can be removed.',
1366
+ 'mcp.param.changeFind': 'The exact text to replace in the field at the path, written as find_text reported it (same capitals and accents). It matches whole words only.',
1367
+ 'mcp.param.changeReplace': 'The new text for find. It is plain text, not Markdown. "" deletes it.',
1368
+ 'mcp.param.changeOccurrences': 'Which occurrences of find to change, numbered from 1 as find_text lists them. Leave it out to change them all.',
1338
1369
  'mcp.param.message': 'A short note about the change, kept in the history.',
1339
1370
  'mcp.param.content': 'The content of the entry, in the form get_document returns: { slug?, path?, fields, slots }. A slot of { enabled: false } is switched off.',
1340
1371
  'mcp.param.translateId': 'The document id of the page, entry or global, in any language it already has.',
@@ -12,6 +12,7 @@ import { realInsideSync } from '../content/shipped-images.js';
12
12
  import { InlayError } from '../errors.js';
13
13
  import { buildRegistry } from '../registry/registry.js';
14
14
  import { bundleSite } from './bundle.js';
15
+ import { publicClashes, publicClashError } from './public-files.js';
15
16
  import { sign } from './keys.js';
16
17
  import { contentPath, manifestOfRegistry, sha256Hex } from './manifest.js';
17
18
  /** Every regular file under `dir`, as `/`-separated paths relative to it. Dotfiles and symlinks are left out. */
@@ -82,6 +83,9 @@ export async function packRelease(opts) {
82
83
  }
83
84
  const publicDir = join(dir, 'public');
84
85
  if (existsSync(publicDir)) {
86
+ const [clash] = await publicClashes(publicDir, registry);
87
+ if (clash)
88
+ throw publicClashError(clash);
85
89
  for (const path of await listFiles(publicDir, true)) {
86
90
  await mkdir(dirname(join(tmp, 'public', path)), { recursive: true });
87
91
  await copyFile(join(publicDir, path), join(tmp, 'public', path));
@@ -0,0 +1,14 @@
1
+ import type { Registry } from '../registry/registry.js';
2
+ import { InlayError } from '../errors.js';
3
+ /** A `public/` file whose root address is taken. `file` is relative to `public/`; `path` is `'/' + file`. */
4
+ export interface PublicClash {
5
+ file: string;
6
+ path: string;
7
+ kind: 'reserved' | 'route' | 'redirect' | 'page';
8
+ }
9
+ /** The `public/` files that would be served at a root address Inlay or the site already uses. */
10
+ export declare function publicClashes(publicDir: string, registry: Pick<Registry, 'getRoutePaths' | 'redirects' | 'locales' | 'defaultLocale'> & {
11
+ site: Pick<Registry['site'], 'singletons'>;
12
+ }): Promise<PublicClash[]>;
13
+ export declare function publicClashMessage(clash: PublicClash): string;
14
+ export declare function publicClashError(clash: PublicClash): InlayError;
@@ -0,0 +1,43 @@
1
+ import { InlayError } from '../errors.js';
2
+ import { t } from '../messages/index.js';
3
+ import { isReserved, singletonPath } from '../site/paths.js';
4
+ import { listFiles } from './pack.js';
5
+ const MESSAGES = {
6
+ reserved: 'error.publicReserved',
7
+ route: 'error.publicRoute',
8
+ redirect: 'error.publicRedirect',
9
+ page: 'error.publicPage',
10
+ };
11
+ /** The `public/` files that would be served at a root address Inlay or the site already uses. */
12
+ export async function publicClashes(publicDir, registry) {
13
+ const pages = new Set();
14
+ for (const def of registry.site.singletons) {
15
+ for (const locale of registry.locales) {
16
+ const p = singletonPath(def, locale, registry.defaultLocale);
17
+ if (p !== null)
18
+ pages.add(p);
19
+ }
20
+ }
21
+ const redirects = new Set(registry.redirects.map((r) => r.from));
22
+ const out = [];
23
+ for (const file of await listFiles(publicDir, true)) {
24
+ if (!(file.split('/').at(-1) ?? '').includes('.'))
25
+ continue;
26
+ const path = `/${file}`;
27
+ if (isReserved(path))
28
+ out.push({ file, path, kind: 'reserved' });
29
+ else if (registry.getRoutePaths.has(path))
30
+ out.push({ file, path, kind: 'route' });
31
+ else if (redirects.has(path))
32
+ out.push({ file, path, kind: 'redirect' });
33
+ else if (pages.has(path))
34
+ out.push({ file, path, kind: 'page' });
35
+ }
36
+ return out.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
37
+ }
38
+ export function publicClashMessage(clash) {
39
+ return t(MESSAGES[clash.kind], { file: clash.file, path: clash.path });
40
+ }
41
+ export function publicClashError(clash) {
42
+ return new InlayError('release', MESSAGES[clash.kind], { file: clash.file, path: clash.path });
43
+ }
@@ -7,5 +7,7 @@ export type ReleaseFit = 'ok' | 'warn' | 'tooOld' | 'tooNew';
7
7
  export declare function runningWindow(): ReleaseWindow;
8
8
  /** Whether a release packed with `packed` runs in `window`: packed with the oldest version or later, and not a newer minor than the host. */
9
9
  export declare function releaseFit(packed: string, window?: ReleaseWindow): ReleaseFit;
10
+ /** Whether `version` is `min` or later, ignoring a prerelease suffix. False when `version` doesn't parse. */
11
+ export declare function atLeastVersion(version: string, min: string): boolean;
10
12
  /** A stored release's `inlay_range` without its leading caret. */
11
13
  export declare function packedVersion(range: string): string;
@@ -28,6 +28,12 @@ export function releaseFit(packed, window = runningWindow()) {
28
28
  return 'warn';
29
29
  return 'ok';
30
30
  }
31
+ /** Whether `version` is `min` or later, ignoring a prerelease suffix. False when `version` doesn't parse. */
32
+ export function atLeastVersion(version, min) {
33
+ const have = parts(version);
34
+ const want = parts(min);
35
+ return have !== null && want !== null && compare(have, want) >= 0;
36
+ }
31
37
  /** A stored release's `inlay_range` without its leading caret. */
32
38
  export function packedVersion(range) {
33
39
  return range.startsWith('^') ? range.slice(1) : range;
@@ -1,6 +1,6 @@
1
1
  import type { ShippedReport } from './content/shipped.js';
2
2
  import type { ContentIssue } from './types.js';
3
- export type ProblemCode = 'shipped_content' | 'release_import' | 'release_forbidden';
3
+ export type ProblemCode = 'shipped_content' | 'release_import' | 'release_forbidden' | 'public_clash';
4
4
  /** One thing that stops the database from being brought up to date. `message` is written for the developer. */
5
5
  export interface CheckProblem {
6
6
  code: ProblemCode;
@@ -0,0 +1,12 @@
1
+ import type { RichTextDoc, RichTextText } from './schema.js';
2
+ export interface TextPiece {
3
+ node: RichTextText;
4
+ start: number;
5
+ end: number;
6
+ }
7
+ export interface TextRun {
8
+ text: string;
9
+ pieces: TextPiece[];
10
+ }
11
+ /** The text of a document in runs: one per block, split again at each hard break and image. Runs with no text are left out. */
12
+ export declare function textRuns(doc: RichTextDoc): TextRun[];
@@ -0,0 +1,31 @@
1
+ /** The text of a document in runs: one per block, split again at each hard break and image. Runs with no text are left out. */
2
+ export function textRuns(doc) {
3
+ const runs = [];
4
+ let current = { text: '', pieces: [] };
5
+ const flush = () => {
6
+ if (current.pieces.length > 0)
7
+ runs.push(current);
8
+ current = { text: '', pieces: [] };
9
+ };
10
+ const walk = (node) => {
11
+ if (node.type === 'text') {
12
+ if (node.text === '')
13
+ return;
14
+ current.pieces.push({ node, start: current.text.length, end: current.text.length + node.text.length });
15
+ current.text += node.text;
16
+ return;
17
+ }
18
+ if (node.type === 'hardBreak' || node.type === 'image') {
19
+ flush();
20
+ return;
21
+ }
22
+ flush();
23
+ for (const child of (node.content ?? []))
24
+ walk(child);
25
+ flush();
26
+ };
27
+ for (const node of doc.content)
28
+ walk(node);
29
+ flush();
30
+ return runs;
31
+ }
@@ -3,3 +3,5 @@ export declare function inlayVersion(): string;
3
3
  export declare const OLDEST_RELEASE = "0.5.0";
4
4
  /** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
5
5
  export declare const NEXT_OLDEST_RELEASE: string | null;
6
+ /** The first Inlay version whose releases serve their `public/` files at the site root too. */
7
+ export declare const ROOT_PUBLIC_FILES_SINCE = "0.7.0";
@@ -7,3 +7,5 @@ export function inlayVersion() {
7
7
  export const OLDEST_RELEASE = '0.5.0';
8
8
  /** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
9
9
  export const NEXT_OLDEST_RELEASE = null;
10
+ /** The first Inlay version whose releases serve their `public/` files at the site root too. */
11
+ export const ROOT_PUBLIC_FILES_SINCE = '0.7.0';
@@ -15,6 +15,12 @@ export interface SiteSource {
15
15
  shippedFiles?: ReadonlyMap<string, string>;
16
16
  /** As `shippedFiles`, only the images `.md` files the site imports name. */
17
17
  codeFiles?: ReadonlyMap<string, string>;
18
+ /** The release manifest; absent for a site run from its code, which always serves public files at the root. */
19
+ manifest?: {
20
+ inlay: {
21
+ version: string;
22
+ };
23
+ };
18
24
  }
19
25
  /** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
20
26
  export declare function sourceFromConfig(loaded: LoadedConfig): SiteSource;
package/dist/host/app.js CHANGED
@@ -7,6 +7,8 @@ import { openDatabase } from '../core/db/connection.js';
7
7
  import { InlayError } from '../core/errors.js';
8
8
  import { t } from '../core/messages/index.js';
9
9
  import { defineSite } from '../core/registry/define.js';
10
+ import { atLeastVersion } from '../core/release/window.js';
11
+ import { ROOT_PUBLIC_FILES_SINCE } from '../core/version.js';
10
12
  import { PREVIEW_RELEASE_HEADER, registerPreviewProxy } from './preview-proxy.js';
11
13
  import { adminHostHooks } from './hooks.js';
12
14
  import { registerPushRoutes } from './push.js';
@@ -94,6 +96,7 @@ export async function createSiteApp(config, source, opts) {
94
96
  cdn: config.cdn,
95
97
  publicMaxAge: config.publicMaxAge,
96
98
  ...(source?.publicDir != null && { publicDir: source.publicDir }),
99
+ rootPublicFiles: source?.manifest === undefined || atLeastVersion(source.manifest.inlay.version, ROOT_PUBLIC_FILES_SINCE),
97
100
  secrets: config.secrets(source?.site.secrets ?? []),
98
101
  ...(opts.fetch && { fetch: opts.fetch }),
99
102
  content: opts.content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inlaycms",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A code-first CMS for content sites: templates, schemas and content in code, one SQLite file, signed releases.",
5
5
  "license": "MIT",
6
6
  "repository": {