@adatechnology/content-contracts 0.1.0 → 0.2.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/dist/index.cjs +281 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +227 -3
- package/dist/index.d.ts +227 -3
- package/dist/index.js +256 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,35 +28,55 @@ __export(index_exports, {
|
|
|
28
28
|
DEFAULT_LINK_REL: () => DEFAULT_LINK_REL,
|
|
29
29
|
DEFAULT_POST_PATH_TEMPLATE: () => DEFAULT_POST_PATH_TEMPLATE,
|
|
30
30
|
DEFAULT_PUBLIC_CACHE_CONTROL: () => DEFAULT_PUBLIC_CACHE_CONTROL,
|
|
31
|
+
DEFAULT_SHORT_SLUG_LENGTH: () => DEFAULT_SHORT_SLUG_LENGTH,
|
|
31
32
|
DEFAULT_WORDS_PER_MINUTE: () => DEFAULT_WORDS_PER_MINUTE,
|
|
32
33
|
DuplicateSlugError: () => DuplicateSlugError,
|
|
33
34
|
ImageStorageDisabledError: () => ImageStorageDisabledError,
|
|
34
35
|
InvalidCoverImageError: () => InvalidCoverImageError,
|
|
35
36
|
InvalidSlugError: () => InvalidSlugError,
|
|
37
|
+
NotATemplateError: () => NotATemplateError,
|
|
36
38
|
POST_EVENT: () => POST_EVENT,
|
|
37
39
|
POST_LIMITS: () => POST_LIMITS,
|
|
40
|
+
POST_SORT_FIELDS: () => POST_SORT_FIELDS,
|
|
38
41
|
POST_STATUS: () => POST_STATUS,
|
|
39
42
|
POST_STATUSES: () => POST_STATUSES,
|
|
43
|
+
PT_BR_STOP_WORDS: () => PT_BR_STOP_WORDS,
|
|
40
44
|
PostNotFoundError: () => PostNotFoundError,
|
|
45
|
+
PostNotPublishedError: () => PostNotPublishedError,
|
|
46
|
+
RECURRENCE_FREQUENCIES: () => RECURRENCE_FREQUENCIES,
|
|
47
|
+
RECURRENCE_FREQUENCY: () => RECURRENCE_FREQUENCY,
|
|
48
|
+
RecurrenceNotFoundError: () => RecurrenceNotFoundError,
|
|
49
|
+
RepublishDateInFutureError: () => RepublishDateInFutureError,
|
|
50
|
+
SHORT_ID_LENGTH: () => SHORT_ID_LENGTH,
|
|
41
51
|
SLUG_MAX_LENGTH: () => SLUG_MAX_LENGTH,
|
|
42
52
|
TAGS_MAX_COUNT: () => TAGS_MAX_COUNT,
|
|
43
53
|
TAG_MAX_LENGTH: () => TAG_MAX_LENGTH,
|
|
54
|
+
TemplateNotPublishableError: () => TemplateNotPublishableError,
|
|
44
55
|
buildAtomFeed: () => buildAtomFeed,
|
|
45
56
|
buildExcerpt: () => buildExcerpt,
|
|
57
|
+
buildPostPath: () => buildPostPath,
|
|
58
|
+
buildPostRef: () => buildPostRef,
|
|
46
59
|
buildPostUrl: () => buildPostUrl,
|
|
47
60
|
buildRssFeed: () => buildRssFeed,
|
|
61
|
+
buildShortSlug: () => buildShortSlug,
|
|
48
62
|
buildSitemapXml: () => buildSitemapXml,
|
|
63
|
+
buildTagLabels: () => buildTagLabels,
|
|
49
64
|
countWords: () => countWords,
|
|
65
|
+
createFromTemplateSchema: () => createFromTemplateSchema,
|
|
50
66
|
createHeadingIdGenerator: () => createHeadingIdGenerator,
|
|
51
67
|
createPostSchema: () => createPostSchema,
|
|
68
|
+
createRecurrenceSchema: () => createRecurrenceSchema,
|
|
52
69
|
documentToPlainText: () => documentToPlainText,
|
|
53
70
|
escapeHtml: () => escapeHtml,
|
|
54
71
|
escapeXml: () => escapeXml,
|
|
55
72
|
estimateReadingTimeMinutes: () => estimateReadingTimeMinutes,
|
|
73
|
+
formatTagLabel: () => formatTagLabel,
|
|
56
74
|
httpUrlSchema: () => httpUrlSchema,
|
|
57
75
|
inlineToPlainText: () => inlineToPlainText,
|
|
58
76
|
isAbsoluteHttpUrl: () => isAbsoluteHttpUrl,
|
|
77
|
+
isCanonicalPostRef: () => isCanonicalPostRef,
|
|
59
78
|
isPostStatus: () => isPostStatus,
|
|
79
|
+
isShortId: () => isShortId,
|
|
60
80
|
isValidSlug: () => isValidSlug,
|
|
61
81
|
listPostsQuerySchema: () => listPostsQuerySchema,
|
|
62
82
|
listPublishedPostsQuerySchema: () => listPublishedPostsQuerySchema,
|
|
@@ -65,16 +85,21 @@ __export(index_exports, {
|
|
|
65
85
|
normalizeTags: () => normalizeTags,
|
|
66
86
|
parseInline: () => parseInline,
|
|
67
87
|
parseMarkdown: () => parseMarkdown,
|
|
88
|
+
parsePostPath: () => parsePostPath,
|
|
89
|
+
parsePostRef: () => parsePostRef,
|
|
68
90
|
postFieldsSchema: () => postFieldsSchema,
|
|
69
91
|
publishPostSchema: () => publishPostSchema,
|
|
70
92
|
renderMarkdownDocument: () => renderMarkdownDocument,
|
|
71
93
|
renderMarkdownToHtml: () => renderMarkdownToHtml,
|
|
94
|
+
republishPostSchema: () => republishPostSchema,
|
|
72
95
|
resolveHeadingLevel: () => resolveHeadingLevel,
|
|
73
96
|
sanitizeImageUrl: () => sanitizeImageUrl,
|
|
74
97
|
sanitizeLinkUrl: () => sanitizeLinkUrl,
|
|
98
|
+
saveAsTemplateSchema: () => saveAsTemplateSchema,
|
|
75
99
|
slugSchema: () => slugSchema,
|
|
76
100
|
slugify: () => slugify,
|
|
77
101
|
updatePostSchema: () => updatePostSchema,
|
|
102
|
+
updateRecurrenceSchema: () => updateRecurrenceSchema,
|
|
78
103
|
withSlugSuffix: () => withSlugSuffix
|
|
79
104
|
});
|
|
80
105
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -91,6 +116,11 @@ function isPostStatus(value) {
|
|
|
91
116
|
return typeof value === "string" && POST_STATUSES.includes(value);
|
|
92
117
|
}
|
|
93
118
|
__name(isPostStatus, "isPostStatus");
|
|
119
|
+
var RECURRENCE_FREQUENCY = {
|
|
120
|
+
WEEKLY: "weekly",
|
|
121
|
+
MONTHLY: "monthly"
|
|
122
|
+
};
|
|
123
|
+
var RECURRENCE_FREQUENCIES = Object.values(RECURRENCE_FREQUENCY);
|
|
94
124
|
|
|
95
125
|
// src/errors.ts
|
|
96
126
|
var ContentError = class extends Error {
|
|
@@ -111,7 +141,12 @@ var CONTENT_ERROR_CODES = {
|
|
|
111
141
|
INVALID_SLUG: "CONTENT_INVALID_SLUG",
|
|
112
142
|
CONFIG_MISSING: "CONTENT_CONFIG_MISSING",
|
|
113
143
|
INVALID_IMAGE: "CONTENT_INVALID_IMAGE",
|
|
114
|
-
IMAGE_STORAGE_DISABLED: "CONTENT_IMAGE_STORAGE_DISABLED"
|
|
144
|
+
IMAGE_STORAGE_DISABLED: "CONTENT_IMAGE_STORAGE_DISABLED",
|
|
145
|
+
NOT_A_TEMPLATE: "CONTENT_NOT_A_TEMPLATE",
|
|
146
|
+
TEMPLATE_NOT_PUBLISHABLE: "CONTENT_TEMPLATE_NOT_PUBLISHABLE",
|
|
147
|
+
NOT_PUBLISHED: "CONTENT_NOT_PUBLISHED",
|
|
148
|
+
REPUBLISH_DATE_IN_FUTURE: "CONTENT_REPUBLISH_DATE_IN_FUTURE",
|
|
149
|
+
RECURRENCE_NOT_FOUND: "CONTENT_RECURRENCE_NOT_FOUND"
|
|
115
150
|
};
|
|
116
151
|
var PostNotFoundError = class extends ContentError {
|
|
117
152
|
static {
|
|
@@ -176,6 +211,58 @@ var ImageStorageDisabledError = class extends ContentError {
|
|
|
176
211
|
super("Envio de imagem n\xE3o configurado.", 501, CONTENT_ERROR_CODES.IMAGE_STORAGE_DISABLED);
|
|
177
212
|
}
|
|
178
213
|
};
|
|
214
|
+
var NotATemplateError = class extends ContentError {
|
|
215
|
+
static {
|
|
216
|
+
__name(this, "NotATemplateError");
|
|
217
|
+
}
|
|
218
|
+
postId;
|
|
219
|
+
constructor(postId) {
|
|
220
|
+
super("Este post n\xE3o \xE9 um modelo.", 422, CONTENT_ERROR_CODES.NOT_A_TEMPLATE, {
|
|
221
|
+
postId
|
|
222
|
+
}), this.postId = postId;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var TemplateNotPublishableError = class extends ContentError {
|
|
226
|
+
static {
|
|
227
|
+
__name(this, "TemplateNotPublishableError");
|
|
228
|
+
}
|
|
229
|
+
postId;
|
|
230
|
+
constructor(postId) {
|
|
231
|
+
super("Modelo n\xE3o pode ser publicado: crie um post a partir dele.", 422, CONTENT_ERROR_CODES.TEMPLATE_NOT_PUBLISHABLE, {
|
|
232
|
+
postId
|
|
233
|
+
}), this.postId = postId;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var PostNotPublishedError = class extends ContentError {
|
|
237
|
+
static {
|
|
238
|
+
__name(this, "PostNotPublishedError");
|
|
239
|
+
}
|
|
240
|
+
postId;
|
|
241
|
+
constructor(postId) {
|
|
242
|
+
super("S\xF3 post publicado pode ser republicado.", 422, CONTENT_ERROR_CODES.NOT_PUBLISHED, {
|
|
243
|
+
postId
|
|
244
|
+
}), this.postId = postId;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var RepublishDateInFutureError = class extends ContentError {
|
|
248
|
+
static {
|
|
249
|
+
__name(this, "RepublishDateInFutureError");
|
|
250
|
+
}
|
|
251
|
+
constructor() {
|
|
252
|
+
super("A nova data n\xE3o pode ser futura: o post sairia do ar at\xE9 l\xE1.", 422, CONTENT_ERROR_CODES.REPUBLISH_DATE_IN_FUTURE);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var RecurrenceNotFoundError = class extends ContentError {
|
|
256
|
+
static {
|
|
257
|
+
__name(this, "RecurrenceNotFoundError");
|
|
258
|
+
}
|
|
259
|
+
reference;
|
|
260
|
+
constructor(reference) {
|
|
261
|
+
super("Recorr\xEAncia n\xE3o encontrada.", 404, CONTENT_ERROR_CODES.RECURRENCE_NOT_FOUND, {
|
|
262
|
+
reference
|
|
263
|
+
}), this.reference = reference;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
179
266
|
|
|
180
267
|
// src/schemas.ts
|
|
181
268
|
var import_zod = require("zod");
|
|
@@ -201,6 +288,58 @@ function withSlugSuffix(slug, attempt) {
|
|
|
201
288
|
return `${slug.slice(0, SLUG_MAX_LENGTH - suffix.length).replace(/-+$/g, "")}${suffix}`;
|
|
202
289
|
}
|
|
203
290
|
__name(withSlugSuffix, "withSlugSuffix");
|
|
291
|
+
var DEFAULT_SHORT_SLUG_LENGTH = 60;
|
|
292
|
+
var PT_BR_STOP_WORDS = [
|
|
293
|
+
"a",
|
|
294
|
+
"as",
|
|
295
|
+
"o",
|
|
296
|
+
"os",
|
|
297
|
+
"um",
|
|
298
|
+
"uma",
|
|
299
|
+
"uns",
|
|
300
|
+
"umas",
|
|
301
|
+
"de",
|
|
302
|
+
"da",
|
|
303
|
+
"das",
|
|
304
|
+
"do",
|
|
305
|
+
"dos",
|
|
306
|
+
"em",
|
|
307
|
+
"na",
|
|
308
|
+
"nas",
|
|
309
|
+
"no",
|
|
310
|
+
"nos",
|
|
311
|
+
"e",
|
|
312
|
+
"ou",
|
|
313
|
+
"para",
|
|
314
|
+
"pra",
|
|
315
|
+
"pro",
|
|
316
|
+
"por",
|
|
317
|
+
"pelo",
|
|
318
|
+
"pela",
|
|
319
|
+
"pelos",
|
|
320
|
+
"pelas",
|
|
321
|
+
"com",
|
|
322
|
+
"sem",
|
|
323
|
+
"ao",
|
|
324
|
+
"aos",
|
|
325
|
+
"que",
|
|
326
|
+
"se"
|
|
327
|
+
];
|
|
328
|
+
function buildShortSlug(title, options = {}) {
|
|
329
|
+
const maxLength = Math.min(options.maxLength ?? DEFAULT_SHORT_SLUG_LENGTH, SLUG_MAX_LENGTH);
|
|
330
|
+
const words = slugify(title).split("-").filter(Boolean);
|
|
331
|
+
const stop = new Set(options.stopWords === false ? [] : options.stopWords ?? PT_BR_STOP_WORDS);
|
|
332
|
+
const meaningful = words.filter((word) => !stop.has(word));
|
|
333
|
+
const kept = meaningful.length > 0 ? meaningful : words;
|
|
334
|
+
let slug = "";
|
|
335
|
+
for (const word of kept) {
|
|
336
|
+
const next = slug ? `${slug}-${word}` : word;
|
|
337
|
+
if (next.length > maxLength) break;
|
|
338
|
+
slug = next;
|
|
339
|
+
}
|
|
340
|
+
return slug || (kept[0] ?? "").slice(0, maxLength).replace(/-+$/g, "");
|
|
341
|
+
}
|
|
342
|
+
__name(buildShortSlug, "buildShortSlug");
|
|
204
343
|
|
|
205
344
|
// src/tags.ts
|
|
206
345
|
var TAG_MAX_LENGTH = 40;
|
|
@@ -221,6 +360,25 @@ function normalizeTags(values) {
|
|
|
221
360
|
return result.slice(0, TAGS_MAX_COUNT);
|
|
222
361
|
}
|
|
223
362
|
__name(normalizeTags, "normalizeTags");
|
|
363
|
+
function buildTagLabels(params) {
|
|
364
|
+
const labels = {};
|
|
365
|
+
for (const value of params.typed) {
|
|
366
|
+
const tag = normalizeTag(value);
|
|
367
|
+
if (!tag) continue;
|
|
368
|
+
const typed = value.trim().replace(/\s+/g, " ").slice(0, TAG_MAX_LENGTH);
|
|
369
|
+
const label = params.explicit?.[tag]?.trim() || (typed !== tag ? typed : void 0) || params.previous?.[tag];
|
|
370
|
+
if (label && label !== tag) labels[tag] = label;
|
|
371
|
+
}
|
|
372
|
+
return labels;
|
|
373
|
+
}
|
|
374
|
+
__name(buildTagLabels, "buildTagLabels");
|
|
375
|
+
function formatTagLabel(tag, labels) {
|
|
376
|
+
const stored = labels?.[tag];
|
|
377
|
+
if (stored) return stored;
|
|
378
|
+
const spaced = tag.replace(/-+/g, " ").trim();
|
|
379
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
380
|
+
}
|
|
381
|
+
__name(formatTagLabel, "formatTagLabel");
|
|
224
382
|
|
|
225
383
|
// src/schemas.ts
|
|
226
384
|
var POST_LIMITS = {
|
|
@@ -251,6 +409,8 @@ var postFieldsSchema = import_zod.z.object({
|
|
|
251
409
|
coverImageUrl: httpUrlSchema.nullable().optional(),
|
|
252
410
|
coverImageAlt: optionalText(POST_LIMITS.IMAGE_ALT),
|
|
253
411
|
tags: import_zod.z.array(import_zod.z.string().trim().min(1).max(TAG_MAX_LENGTH)).max(TAGS_MAX_COUNT).optional(),
|
|
412
|
+
/** Rótulo de exibição por tag (chave = tag normalizada). Sem rótulo, vale o texto digitado. */
|
|
413
|
+
tagLabels: import_zod.z.record(import_zod.z.string().trim().min(1).max(TAG_MAX_LENGTH)).optional(),
|
|
254
414
|
authorName: optionalText(POST_LIMITS.AUTHOR_NAME),
|
|
255
415
|
seoTitle: optionalText(POST_LIMITS.SEO_TITLE),
|
|
256
416
|
seoDescription: optionalText(POST_LIMITS.SEO_DESCRIPTION),
|
|
@@ -266,18 +426,62 @@ var publishPostSchema = import_zod.z.object({
|
|
|
266
426
|
}).optional()
|
|
267
427
|
}).strict();
|
|
268
428
|
var pageSchema = import_zod.z.coerce.number().int().min(1).max(1e4).default(1);
|
|
429
|
+
var POST_SORT_FIELDS = [
|
|
430
|
+
"title",
|
|
431
|
+
"status",
|
|
432
|
+
"publishedAt",
|
|
433
|
+
"updatedAt"
|
|
434
|
+
];
|
|
269
435
|
var listPostsQuerySchema = import_zod.z.object({
|
|
270
436
|
page: pageSchema,
|
|
271
437
|
pageSize: import_zod.z.coerce.number().int().min(1).max(POST_LIMITS.ADMIN_PAGE_SIZE).default(20),
|
|
272
438
|
status: import_zod.z.enum(POST_STATUSES).optional(),
|
|
273
|
-
tag
|
|
274
|
-
|
|
439
|
+
/** Uma tag, ou várias separadas por vírgula (basta ter UMA delas). */
|
|
440
|
+
tag: import_zod.z.string().trim().min(1).max(TAG_MAX_LENGTH * TAGS_MAX_COUNT).optional(),
|
|
441
|
+
search: import_zod.z.string().trim().min(1).max(POST_LIMITS.SEARCH).optional(),
|
|
442
|
+
/** Padrão: `updatedAt` (o que o painel mexeu por último). */
|
|
443
|
+
sort: import_zod.z.enum(POST_SORT_FIELDS).default("updatedAt"),
|
|
444
|
+
order: import_zod.z.enum([
|
|
445
|
+
"asc",
|
|
446
|
+
"desc"
|
|
447
|
+
]).default("desc"),
|
|
448
|
+
/** `true`: só modelos. Ausente/`false`: só posts (modelo nunca aparece misturado na lista). */
|
|
449
|
+
isTemplate: import_zod.z.union([
|
|
450
|
+
import_zod.z.boolean(),
|
|
451
|
+
import_zod.z.enum([
|
|
452
|
+
"true",
|
|
453
|
+
"false"
|
|
454
|
+
])
|
|
455
|
+
]).transform((value) => value === true || value === "true").optional()
|
|
275
456
|
});
|
|
276
457
|
var listPublishedPostsQuerySchema = import_zod.z.object({
|
|
277
458
|
page: pageSchema,
|
|
278
459
|
pageSize: import_zod.z.coerce.number().int().min(1).max(POST_LIMITS.PUBLIC_PAGE_SIZE).default(10),
|
|
279
460
|
tag: import_zod.z.string().trim().min(1).max(TAG_MAX_LENGTH).optional()
|
|
280
461
|
});
|
|
462
|
+
var isoInstant = import_zod.z.string().datetime({
|
|
463
|
+
offset: true
|
|
464
|
+
});
|
|
465
|
+
var saveAsTemplateSchema = import_zod.z.object({
|
|
466
|
+
title: import_zod.z.string().trim().min(1).max(POST_LIMITS.TITLE).optional()
|
|
467
|
+
}).strict();
|
|
468
|
+
var createFromTemplateSchema = import_zod.z.object({
|
|
469
|
+
title: import_zod.z.string().trim().min(1).max(POST_LIMITS.TITLE).optional(),
|
|
470
|
+
slug: slugSchema.optional()
|
|
471
|
+
}).strict();
|
|
472
|
+
var republishPostSchema = import_zod.z.object({
|
|
473
|
+
publishedAt: isoInstant.optional()
|
|
474
|
+
}).strict();
|
|
475
|
+
var createRecurrenceSchema = import_zod.z.object({
|
|
476
|
+
templateId: import_zod.z.string().uuid(),
|
|
477
|
+
frequency: import_zod.z.enum(RECURRENCE_FREQUENCIES),
|
|
478
|
+
/** Primeira publicação automática. */
|
|
479
|
+
startsAt: isoInstant
|
|
480
|
+
}).strict();
|
|
481
|
+
var updateRecurrenceSchema = import_zod.z.object({
|
|
482
|
+
isActive: import_zod.z.boolean().optional(),
|
|
483
|
+
nextRunAt: isoInstant.optional()
|
|
484
|
+
}).strict();
|
|
281
485
|
|
|
282
486
|
// src/providers.ts
|
|
283
487
|
var POST_EVENT = {
|
|
@@ -285,13 +489,60 @@ var POST_EVENT = {
|
|
|
285
489
|
UPDATED: "updated",
|
|
286
490
|
PUBLISHED: "published",
|
|
287
491
|
UNPUBLISHED: "unpublished",
|
|
288
|
-
ARCHIVED: "archived"
|
|
492
|
+
ARCHIVED: "archived",
|
|
493
|
+
REPUBLISHED: "republished"
|
|
289
494
|
};
|
|
290
495
|
var DEFAULT_ADMIN_SCOPES = [
|
|
291
496
|
"content:admin"
|
|
292
497
|
];
|
|
293
498
|
var DEFAULT_PUBLIC_CACHE_CONTROL = "public, max-age=60, s-maxage=300, stale-while-revalidate=600";
|
|
294
499
|
|
|
500
|
+
// src/postPath.ts
|
|
501
|
+
var SHORT_ID_LENGTH = 6;
|
|
502
|
+
var SHORT_ID_PATTERN = /^[0-9a-z]{6}$/;
|
|
503
|
+
var REF_PATTERN = /^([0-9a-z]{6})-(.+)$/;
|
|
504
|
+
function isShortId(value) {
|
|
505
|
+
return SHORT_ID_PATTERN.test(value);
|
|
506
|
+
}
|
|
507
|
+
__name(isShortId, "isShortId");
|
|
508
|
+
function buildPostRef(params) {
|
|
509
|
+
return `${params.shortId}-${params.slug}`;
|
|
510
|
+
}
|
|
511
|
+
__name(buildPostRef, "buildPostRef");
|
|
512
|
+
function buildPostPath(params) {
|
|
513
|
+
const base = params.basePath.replace(/\/+$/g, "");
|
|
514
|
+
return `${base}/${encodeURIComponent(buildPostRef(params))}`;
|
|
515
|
+
}
|
|
516
|
+
__name(buildPostPath, "buildPostPath");
|
|
517
|
+
function parsePostRef(ref) {
|
|
518
|
+
const slug = ref.trim().toLowerCase();
|
|
519
|
+
const match = REF_PATTERN.exec(slug);
|
|
520
|
+
return match?.[1] ? {
|
|
521
|
+
shortId: match[1],
|
|
522
|
+
slug
|
|
523
|
+
} : {
|
|
524
|
+
slug
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
__name(parsePostRef, "parsePostRef");
|
|
528
|
+
function parsePostPath(params) {
|
|
529
|
+
const base = params.basePath.replace(/\/+$/g, "");
|
|
530
|
+
const clean = params.path.split(/[?#]/)[0] ?? "";
|
|
531
|
+
if (!clean.startsWith(`${base}/`)) return void 0;
|
|
532
|
+
const rest = clean.slice(base.length + 1).replace(/\/+$/g, "");
|
|
533
|
+
if (!rest || rest.includes("/")) return void 0;
|
|
534
|
+
try {
|
|
535
|
+
return parsePostRef(decodeURIComponent(rest));
|
|
536
|
+
} catch {
|
|
537
|
+
return void 0;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
__name(parsePostPath, "parsePostPath");
|
|
541
|
+
function isCanonicalPostRef(params) {
|
|
542
|
+
return params.ref.trim().toLowerCase() === buildPostRef(params);
|
|
543
|
+
}
|
|
544
|
+
__name(isCanonicalPostRef, "isCanonicalPostRef");
|
|
545
|
+
|
|
295
546
|
// src/markdown/sanitizeUrl.ts
|
|
296
547
|
var LINK_SCHEMES = /* @__PURE__ */ new Set([
|
|
297
548
|
"http",
|
|
@@ -1035,7 +1286,7 @@ function escapeXml(value) {
|
|
|
1035
1286
|
__name(escapeXml, "escapeXml");
|
|
1036
1287
|
function buildPostUrl(params) {
|
|
1037
1288
|
const base = params.siteUrl.replace(/\/+$/, "");
|
|
1038
|
-
const path = (params.postPathTemplate ?? DEFAULT_POST_PATH_TEMPLATE).replace("{slug}", encodeURIComponent(params.slug));
|
|
1289
|
+
const path = (params.postPathTemplate ?? DEFAULT_POST_PATH_TEMPLATE).replace("{shortId}", encodeURIComponent(params.shortId ?? "")).replace("{slug}", encodeURIComponent(params.slug));
|
|
1039
1290
|
return `${base}${path.startsWith("/") ? path : `/${path}`}`;
|
|
1040
1291
|
}
|
|
1041
1292
|
__name(buildPostUrl, "buildPostUrl");
|
|
@@ -1123,35 +1374,55 @@ __name(buildSitemapXml, "buildSitemapXml");
|
|
|
1123
1374
|
DEFAULT_LINK_REL,
|
|
1124
1375
|
DEFAULT_POST_PATH_TEMPLATE,
|
|
1125
1376
|
DEFAULT_PUBLIC_CACHE_CONTROL,
|
|
1377
|
+
DEFAULT_SHORT_SLUG_LENGTH,
|
|
1126
1378
|
DEFAULT_WORDS_PER_MINUTE,
|
|
1127
1379
|
DuplicateSlugError,
|
|
1128
1380
|
ImageStorageDisabledError,
|
|
1129
1381
|
InvalidCoverImageError,
|
|
1130
1382
|
InvalidSlugError,
|
|
1383
|
+
NotATemplateError,
|
|
1131
1384
|
POST_EVENT,
|
|
1132
1385
|
POST_LIMITS,
|
|
1386
|
+
POST_SORT_FIELDS,
|
|
1133
1387
|
POST_STATUS,
|
|
1134
1388
|
POST_STATUSES,
|
|
1389
|
+
PT_BR_STOP_WORDS,
|
|
1135
1390
|
PostNotFoundError,
|
|
1391
|
+
PostNotPublishedError,
|
|
1392
|
+
RECURRENCE_FREQUENCIES,
|
|
1393
|
+
RECURRENCE_FREQUENCY,
|
|
1394
|
+
RecurrenceNotFoundError,
|
|
1395
|
+
RepublishDateInFutureError,
|
|
1396
|
+
SHORT_ID_LENGTH,
|
|
1136
1397
|
SLUG_MAX_LENGTH,
|
|
1137
1398
|
TAGS_MAX_COUNT,
|
|
1138
1399
|
TAG_MAX_LENGTH,
|
|
1400
|
+
TemplateNotPublishableError,
|
|
1139
1401
|
buildAtomFeed,
|
|
1140
1402
|
buildExcerpt,
|
|
1403
|
+
buildPostPath,
|
|
1404
|
+
buildPostRef,
|
|
1141
1405
|
buildPostUrl,
|
|
1142
1406
|
buildRssFeed,
|
|
1407
|
+
buildShortSlug,
|
|
1143
1408
|
buildSitemapXml,
|
|
1409
|
+
buildTagLabels,
|
|
1144
1410
|
countWords,
|
|
1411
|
+
createFromTemplateSchema,
|
|
1145
1412
|
createHeadingIdGenerator,
|
|
1146
1413
|
createPostSchema,
|
|
1414
|
+
createRecurrenceSchema,
|
|
1147
1415
|
documentToPlainText,
|
|
1148
1416
|
escapeHtml,
|
|
1149
1417
|
escapeXml,
|
|
1150
1418
|
estimateReadingTimeMinutes,
|
|
1419
|
+
formatTagLabel,
|
|
1151
1420
|
httpUrlSchema,
|
|
1152
1421
|
inlineToPlainText,
|
|
1153
1422
|
isAbsoluteHttpUrl,
|
|
1423
|
+
isCanonicalPostRef,
|
|
1154
1424
|
isPostStatus,
|
|
1425
|
+
isShortId,
|
|
1155
1426
|
isValidSlug,
|
|
1156
1427
|
listPostsQuerySchema,
|
|
1157
1428
|
listPublishedPostsQuerySchema,
|
|
@@ -1160,16 +1431,21 @@ __name(buildSitemapXml, "buildSitemapXml");
|
|
|
1160
1431
|
normalizeTags,
|
|
1161
1432
|
parseInline,
|
|
1162
1433
|
parseMarkdown,
|
|
1434
|
+
parsePostPath,
|
|
1435
|
+
parsePostRef,
|
|
1163
1436
|
postFieldsSchema,
|
|
1164
1437
|
publishPostSchema,
|
|
1165
1438
|
renderMarkdownDocument,
|
|
1166
1439
|
renderMarkdownToHtml,
|
|
1440
|
+
republishPostSchema,
|
|
1167
1441
|
resolveHeadingLevel,
|
|
1168
1442
|
sanitizeImageUrl,
|
|
1169
1443
|
sanitizeLinkUrl,
|
|
1444
|
+
saveAsTemplateSchema,
|
|
1170
1445
|
slugSchema,
|
|
1171
1446
|
slugify,
|
|
1172
1447
|
updatePostSchema,
|
|
1448
|
+
updateRecurrenceSchema,
|
|
1173
1449
|
withSlugSuffix
|
|
1174
1450
|
});
|
|
1175
1451
|
//# sourceMappingURL=index.cjs.map
|