tinyzoo 0.0.0-stage → 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/LICENSE +10 -0
- package/README.md +46 -2
- package/app/app.config.ts +35 -0
- package/app/assets/brand/characters/bright/bird.svg +1 -0
- package/app/assets/brand/characters/bright/bunny.svg +1 -0
- package/app/assets/brand/characters/bright/elephant.svg +1 -0
- package/app/assets/brand/characters/bright/fox.svg +1 -0
- package/app/assets/brand/characters/bright/frog.svg +1 -0
- package/app/assets/brand/characters/bright/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/bee.svg +1 -0
- package/app/assets/brand/characters/muted/bird.svg +1 -0
- package/app/assets/brand/characters/muted/butterfly.svg +1 -0
- package/app/assets/brand/characters/muted/chick.svg +1 -0
- package/app/assets/brand/characters/muted/cow.svg +1 -0
- package/app/assets/brand/characters/muted/deer.svg +1 -0
- package/app/assets/brand/characters/muted/duck.svg +1 -0
- package/app/assets/brand/characters/muted/elephant.svg +1 -0
- package/app/assets/brand/characters/muted/fox.svg +1 -0
- package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
- package/app/assets/brand/characters/muted/koala.svg +1 -0
- package/app/assets/brand/characters/muted/ladybug.svg +1 -0
- package/app/assets/brand/characters/muted/lion.svg +1 -0
- package/app/assets/brand/characters/muted/mouse.svg +1 -0
- package/app/assets/brand/characters/muted/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/owl.svg +1 -0
- package/app/assets/brand/characters/muted/panda.svg +1 -0
- package/app/assets/brand/characters/muted/penguin.svg +1 -0
- package/app/assets/brand/characters/muted/pig.svg +1 -0
- package/app/assets/brand/characters/muted/poodle.svg +1 -0
- package/app/assets/brand/characters/muted/raccoon.svg +1 -0
- package/app/assets/brand/characters/muted/seal.svg +1 -0
- package/app/assets/brand/characters/muted/sheep.svg +1 -0
- package/app/assets/brand/characters/muted/snail.svg +1 -0
- package/app/assets/brand/characters/muted/turtle.svg +1 -0
- package/app/assets/brand/characters/muted/whale.svg +1 -0
- package/app/assets/brand/logo/favicon.svg +1 -0
- package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
- package/app/assets/brand/logo/logo-primary.svg +1 -0
- package/app/assets/brand/logo/mascot-reversed.svg +1 -0
- package/app/assets/brand/logo/mascot.svg +1 -0
- package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
- package/app/assets/brand/logo/wordmark.svg +1 -0
- package/app/assets/css/cms-admin.css +607 -0
- package/app/components/CmsBlocks.vue +30 -0
- package/app/components/CmsCell.vue +16 -0
- package/app/components/CmsCellBadge.vue +18 -0
- package/app/components/CmsCellBlocks.vue +9 -0
- package/app/components/CmsCellBoolean.vue +12 -0
- package/app/components/CmsCellCode.vue +7 -0
- package/app/components/CmsCellColor.vue +13 -0
- package/app/components/CmsCellDate.vue +10 -0
- package/app/components/CmsCellExcerpt.vue +21 -0
- package/app/components/CmsCellGallery.vue +10 -0
- package/app/components/CmsCellGroup.vue +23 -0
- package/app/components/CmsCellNumber.vue +7 -0
- package/app/components/CmsCellRelation.vue +8 -0
- package/app/components/CmsCellText.vue +12 -0
- package/app/components/CmsCellThumb.vue +18 -0
- package/app/components/CmsConfirmDialog.vue +55 -0
- package/app/components/CmsContent.vue +103 -0
- package/app/components/CmsDayPicker.vue +44 -0
- package/app/components/CmsEmptyState.vue +35 -0
- package/app/components/CmsField.vue +111 -0
- package/app/components/CmsFieldBlocks.vue +353 -0
- package/app/components/CmsFieldBoolean.vue +8 -0
- package/app/components/CmsFieldColor.vue +42 -0
- package/app/components/CmsFieldDate.vue +131 -0
- package/app/components/CmsFieldGallery.vue +114 -0
- package/app/components/CmsFieldGroup.vue +53 -0
- package/app/components/CmsFieldMedia.vue +219 -0
- package/app/components/CmsFieldNumber.vue +11 -0
- package/app/components/CmsFieldRelationMany.vue +54 -0
- package/app/components/CmsFieldRelationOne.vue +47 -0
- package/app/components/CmsFieldRichText.vue +45 -0
- package/app/components/CmsFieldSelect.vue +41 -0
- package/app/components/CmsFieldSlug.vue +46 -0
- package/app/components/CmsFieldText.vue +75 -0
- package/app/components/CmsFormSections.vue +150 -0
- package/app/components/CmsHighlight.vue +22 -0
- package/app/components/CmsImage.vue +39 -0
- package/app/components/CmsLinkPicker.vue +122 -0
- package/app/components/CmsLinkTarget.vue +35 -0
- package/app/components/CmsListFilters.vue +107 -0
- package/app/components/CmsLiveNotice.vue +64 -0
- package/app/components/CmsLoadError.vue +24 -0
- package/app/components/CmsMascot.vue +10 -0
- package/app/components/CmsMediaLibrary.vue +114 -0
- package/app/components/CmsMediaPreview.vue +34 -0
- package/app/components/CmsMediaThumb.vue +22 -0
- package/app/components/CmsMoment.vue +42 -0
- package/app/components/CmsNav.vue +39 -0
- package/app/components/CmsPage.vue +86 -0
- package/app/components/CmsPasswordInput.vue +22 -0
- package/app/components/CmsPresence.vue +29 -0
- package/app/components/CmsPreviewPanel.vue +131 -0
- package/app/components/CmsPublishReview.vue +102 -0
- package/app/components/CmsRevisions.vue +195 -0
- package/app/components/CmsRichTextEditor.vue +290 -0
- package/app/components/CmsSearch.vue +99 -0
- package/app/components/CmsSection.vue +20 -0
- package/app/components/CmsSingletonForm.vue +283 -0
- package/app/components/CmsStatusBadge.vue +21 -0
- package/app/components/CmsTime.vue +16 -0
- package/app/components/CmsTranslationRef.vue +27 -0
- package/app/components/CmsTreeList.vue +453 -0
- package/app/components/CmsUnsavedText.vue +34 -0
- package/app/components/CmsWordmark.vue +10 -0
- package/app/composables/useCmsAdminHead.ts +18 -0
- package/app/composables/useCmsCollab.ts +165 -0
- package/app/composables/useCmsConfirm.ts +39 -0
- package/app/composables/useCmsEntryActions.ts +75 -0
- package/app/composables/useCmsFocus.ts +13 -0
- package/app/composables/useCmsForm.ts +273 -0
- package/app/composables/useCmsI18n.ts +185 -0
- package/app/composables/useCmsLinkTargets.ts +84 -0
- package/app/composables/useCmsLive.ts +199 -0
- package/app/composables/useCmsSearch.ts +62 -0
- package/app/composables/useCmsSeo.ts +99 -0
- package/app/composables/useCmsSignedIn.ts +24 -0
- package/app/composables/useCmsUiLocale.ts +24 -0
- package/app/i18n/cs.ts +781 -0
- package/app/i18n/de.ts +781 -0
- package/app/i18n/en.ts +782 -0
- package/app/i18n/types.ts +22 -0
- package/app/layouts/admin.vue +224 -0
- package/app/layouts/cms-auth.vue +37 -0
- package/app/middleware/cms-api-not-a-page.global.ts +10 -0
- package/app/middleware/cms-auth.global.ts +16 -0
- package/app/pages/admin/[entity]/[id].vue +1109 -0
- package/app/pages/admin/[entity]/index.vue +733 -0
- package/app/pages/admin/account.vue +117 -0
- package/app/pages/admin/forgot.vue +50 -0
- package/app/pages/admin/index.vue +184 -0
- package/app/pages/admin/invite/[token].vue +73 -0
- package/app/pages/admin/login.vue +84 -0
- package/app/pages/admin/media.vue +494 -0
- package/app/pages/admin/privacy.vue +193 -0
- package/app/pages/admin/reset/[token].vue +52 -0
- package/app/pages/admin/setup.vue +87 -0
- package/app/pages/admin/styleguide.vue +261 -0
- package/app/pages/admin/team.vue +258 -0
- package/app/plugins/cmsLivePreview.client.ts +20 -0
- package/app/plugins/cmsSignedOut.client.ts +31 -0
- package/app/utils/cmsBlockType.ts +11 -0
- package/app/utils/cmsBrand.ts +38 -0
- package/app/utils/cmsDiff.ts +83 -0
- package/app/utils/cmsFetch.ts +7 -0
- package/app/utils/cmsFocusInvalid.ts +22 -0
- package/app/utils/cmsIssues.ts +128 -0
- package/app/utils/cmsJson.ts +28 -0
- package/app/utils/cmsMedia.ts +63 -0
- package/app/utils/cmsSections.ts +154 -0
- package/app/utils/cmsTime.ts +41 -0
- package/cli/backup.ts +713 -0
- package/cli/breaking.ts +174 -0
- package/cli/content-migrate.ts +239 -0
- package/cli/db.ts +86 -0
- package/cli/export.ts +336 -0
- package/cli/generate.ts +146 -0
- package/cli/import.ts +643 -0
- package/cli/index.ts +140 -0
- package/cli/links-convert.ts +291 -0
- package/cli/seed-engine.ts +705 -0
- package/cli/seed.ts +339 -0
- package/cli/status.ts +49 -0
- package/cli/tar.ts +304 -0
- package/cli/transfer.ts +677 -0
- package/cli/up.ts +27 -0
- package/cli/upgrade.ts +60 -0
- package/cli/versions.ts +60 -0
- package/forms/components/CmsForm.vue +186 -0
- package/forms/index.ts +203 -0
- package/forms/messages.ts +104 -0
- package/forms/retention.ts +48 -0
- package/forms/server/form.get.ts +12 -0
- package/forms/server/form.post.ts +109 -0
- package/forms/server/formSettings.ts +12 -0
- package/forms/server/forms.ts +127 -0
- package/module.ts +373 -0
- package/nuxt.config.ts +43 -0
- package/package.json +99 -3
- package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
- package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
- package/server/api/cms/[entity]/[id].delete.ts +52 -0
- package/server/api/cms/[entity]/[id].get.ts +21 -0
- package/server/api/cms/[entity]/[id].patch.ts +116 -0
- package/server/api/cms/[entity]/_export.get.ts +69 -0
- package/server/api/cms/[entity]/_move.post.ts +81 -0
- package/server/api/cms/[entity]/_order.post.ts +49 -0
- package/server/api/cms/[entity]/_tree.get.ts +41 -0
- package/server/api/cms/[entity]/index.get.ts +62 -0
- package/server/api/cms/[entity]/index.post.ts +38 -0
- package/server/api/cms/[entity]/options.get.ts +55 -0
- package/server/api/cms/_auth/accept.post.ts +33 -0
- package/server/api/cms/_auth/forgot.post.ts +39 -0
- package/server/api/cms/_auth/invite/[token].get.ts +18 -0
- package/server/api/cms/_auth/login.post.ts +42 -0
- package/server/api/cms/_auth/logout.post.ts +7 -0
- package/server/api/cms/_auth/me.get.ts +5 -0
- package/server/api/cms/_auth/me.patch.ts +32 -0
- package/server/api/cms/_auth/password.post.ts +29 -0
- package/server/api/cms/_auth/reset.post.ts +34 -0
- package/server/api/cms/_auth/setup.post.ts +46 -0
- package/server/api/cms/_auth/status.get.ts +18 -0
- package/server/api/cms/_collab/session.get.ts +30 -0
- package/server/api/cms/_collab/socket.ts +51 -0
- package/server/api/cms/_collab/unsaved.delete.ts +16 -0
- package/server/api/cms/_graph.get.ts +20 -0
- package/server/api/cms/_links/resolve.post.ts +17 -0
- package/server/api/cms/_links.get.ts +81 -0
- package/server/api/cms/_live.ts +30 -0
- package/server/api/cms/_media/[id]/usage.get.ts +14 -0
- package/server/api/cms/_media/[id].delete.ts +29 -0
- package/server/api/cms/_media/[id].get.ts +13 -0
- package/server/api/cms/_media/[id].patch.ts +64 -0
- package/server/api/cms/_media/exists.post.ts +15 -0
- package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
- package/server/api/cms/_media/index.get.ts +44 -0
- package/server/api/cms/_media/index.post.ts +147 -0
- package/server/api/cms/_media/raw/[...key].get.ts +85 -0
- package/server/api/cms/_media/raw/[...key].head.ts +2 -0
- package/server/api/cms/_overview.get.ts +87 -0
- package/server/api/cms/_preview.post.ts +17 -0
- package/server/api/cms/_privacy/delete.post.ts +14 -0
- package/server/api/cms/_privacy/export.post.ts +25 -0
- package/server/api/cms/_privacy/lookup.post.ts +27 -0
- package/server/api/cms/_search.get.ts +17 -0
- package/server/api/cms/_singleton/[name].get.ts +19 -0
- package/server/api/cms/_singleton/[name].put.ts +76 -0
- package/server/api/cms/_users/[id]/resend.post.ts +25 -0
- package/server/api/cms/_users/[id].delete.ts +21 -0
- package/server/api/cms/_users/[id].patch.ts +45 -0
- package/server/api/cms/_users/index.get.ts +28 -0
- package/server/api/cms/_users/index.post.ts +39 -0
- package/server/api/content/[entity]/[slug].get.ts +74 -0
- package/server/api/content/[entity]/index.get.ts +100 -0
- package/server/api/content/_global/[name].get.ts +23 -0
- package/server/api/content/_search.get.ts +28 -0
- package/server/api/content/_sitemap.get.ts +8 -0
- package/server/api/content/_tree/[entity].get.ts +31 -0
- package/server/api/content-types.ts.get.ts +17 -0
- package/server/api/health/live.get.ts +10 -0
- package/server/api/health/ready.get.ts +21 -0
- package/server/api/openapi.get.ts +48 -0
- package/server/api/openapi.json.get.ts +32 -0
- package/server/db/driver.ts +8 -0
- package/server/mail/mailer.ts +43 -0
- package/server/middleware/cms-0-headers.ts +37 -0
- package/server/middleware/cms-0-migrate-gate.ts +14 -0
- package/server/middleware/cms-csrf.ts +28 -0
- package/server/middleware/cms-limits.ts +20 -0
- package/server/middleware/cms-redirects.ts +21 -0
- package/server/middleware/cms-session.ts +41 -0
- package/server/middleware/cms-z-plugin-access.ts +15 -0
- package/server/plugins/cms-0-config-check.ts +35 -0
- package/server/plugins/cms-changes.ts +53 -0
- package/server/plugins/cms-content-etag.ts +21 -0
- package/server/plugins/cms-errors.ts +45 -0
- package/server/plugins/cms-migrate.ts +5 -0
- package/server/plugins/cms-plugins.ts +17 -0
- package/server/plugins/cms-search.ts +12 -0
- package/server/plugins/cms-setup-code.ts +15 -0
- package/server/routes/sitemap.xml.get.ts +25 -0
- package/server/store/redis.ts +95 -0
- package/server/store/types.ts +21 -0
- package/server/tasks/cms/retention.ts +10 -0
- package/server/tasks/cms/scheduled.ts +10 -0
- package/server/tasks/cms/search-reindex.ts +12 -0
- package/server/utils/cmsAudit.ts +29 -0
- package/server/utils/cmsAuth.ts +143 -0
- package/server/utils/cmsBlocks.ts +47 -0
- package/server/utils/cmsChanges.ts +222 -0
- package/server/utils/cmsCollab.ts +286 -0
- package/server/utils/cmsCollabServer.ts +451 -0
- package/server/utils/cmsCollate.ts +27 -0
- package/server/utils/cmsContent.ts +376 -0
- package/server/utils/cmsCrud.ts +361 -0
- package/server/utils/cmsCsv.ts +24 -0
- package/server/utils/cmsDb.ts +23 -0
- package/server/utils/cmsDemo.ts +36 -0
- package/server/utils/cmsEmails.ts +125 -0
- package/server/utils/cmsErrors.ts +40 -0
- package/server/utils/cmsFold.ts +17 -0
- package/server/utils/cmsImageSizes.ts +51 -0
- package/server/utils/cmsJson.ts +6 -0
- package/server/utils/cmsLinkAddress.ts +50 -0
- package/server/utils/cmsLinks.ts +248 -0
- package/server/utils/cmsListQuery.ts +93 -0
- package/server/utils/cmsLive.ts +392 -0
- package/server/utils/cmsLocales.ts +96 -0
- package/server/utils/cmsMail.ts +28 -0
- package/server/utils/cmsMediaGc.ts +188 -0
- package/server/utils/cmsMediaKeys.ts +62 -0
- package/server/utils/cmsMigrate.ts +86 -0
- package/server/utils/cmsPreviewDraft.ts +72 -0
- package/server/utils/cmsPrivacy.ts +176 -0
- package/server/utils/cmsPublished.ts +57 -0
- package/server/utils/cmsRange.ts +38 -0
- package/server/utils/cmsRateLimit.ts +82 -0
- package/server/utils/cmsRedirects.ts +160 -0
- package/server/utils/cmsRetention.ts +61 -0
- package/server/utils/cmsRevisions.ts +103 -0
- package/server/utils/cmsScheduler.ts +45 -0
- package/server/utils/cmsScrub.ts +107 -0
- package/server/utils/cmsSearch.ts +354 -0
- package/server/utils/cmsSession.ts +102 -0
- package/server/utils/cmsSetupCode.ts +97 -0
- package/server/utils/cmsSitemap.ts +176 -0
- package/server/utils/cmsStorage.ts +580 -0
- package/server/utils/cmsStore.ts +109 -0
- package/server/utils/cmsTooMany.ts +9 -0
- package/server/utils/cmsTranslationWrite.ts +186 -0
- package/server/utils/cmsTree.ts +251 -0
- package/server/utils/cmsTreeAddress.ts +65 -0
- package/server/utils/cmsUpload.ts +197 -0
- package/server/utils/cmsWebhooks.ts +101 -0
- package/shared/json.ts +11 -0
- package/shared/richtext-editor.ts +56 -0
- package/shared/richtext-normalize.ts +33 -0
- package/shared/richtext-paste.ts +151 -0
- package/shared/storage-delivery.ts +53 -0
- package/src/blocks.ts +624 -0
- package/src/changes.ts +54 -0
- package/src/content-shape.ts +340 -0
- package/src/deprecate.ts +64 -0
- package/src/descriptor.ts +149 -0
- package/src/docs.ts +27 -0
- package/src/emitter.ts +94 -0
- package/src/entity.ts +624 -0
- package/src/errorReport.ts +41 -0
- package/src/fields.ts +465 -0
- package/src/i18n.ts +26 -0
- package/src/index.ts +54 -0
- package/src/linkref.ts +31 -0
- package/src/links.ts +179 -0
- package/src/locales.ts +39 -0
- package/src/media.ts +48 -0
- package/src/migrate.ts +236 -0
- package/src/openapi.ts +377 -0
- package/src/paths.ts +88 -0
- package/src/plugin.ts +505 -0
- package/src/presets.ts +230 -0
- package/src/richtext.ts +88 -0
- package/src/sdk.ts +181 -0
- package/src/search.ts +312 -0
- package/src/seed.ts +225 -0
- package/src/setupCode.ts +30 -0
- package/src/system.ts +219 -0
- package/src/tree.ts +421 -0
- package/src/upgrades.ts +137 -0
- package/starter/.env.example +10 -0
- package/starter/README.md +65 -0
- package/starter/app/app.config.ts +10 -0
- package/starter/app/app.vue +12 -0
- package/starter/app/assets/css/main.css +15 -0
- package/starter/app/components/global/BlockContact.vue +15 -0
- package/starter/app/components/global/BlockCta.vue +15 -0
- package/starter/app/components/global/BlockHero.vue +23 -0
- package/starter/app/components/global/BlockImage.vue +13 -0
- package/starter/app/components/global/BlockText.vue +12 -0
- package/starter/app/composables/useSite.ts +77 -0
- package/starter/app/error.vue +28 -0
- package/starter/app/layouts/default.vue +106 -0
- package/starter/app/lib/cms-content.ts +152 -0
- package/starter/app/pages/[...slug].vue +66 -0
- package/starter/app/pages/hledat.vue +59 -0
- package/starter/app/pages/index.vue +20 -0
- package/starter/cms.config.ts +137 -0
- package/starter/compose.yaml +15 -0
- package/starter/drizzle.config.ts +8 -0
- package/starter/gitignore.txt +8 -0
- package/starter/nuxt.config.ts +13 -0
- package/starter/package.json +38 -0
- package/starter/scripts/typecheck.mjs +38 -0
- package/starter/seed/index.ts +297 -0
- package/starter/seed/media/about.jpg +0 -0
- package/starter/seed/media/hero.jpg +0 -0
- package/starter/seed/media/logo.png +0 -0
- package/starter/seed/media/news-bread.jpg +0 -0
- package/starter/seed/media/news-morning.jpg +0 -0
- package/starter/server/db/migrations/0000_init.sql +269 -0
- package/starter/server/db/migrations/0001_page_tree.sql +5 -0
- package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
- package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
- package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
- package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
- package/starter/server/db/migrations/meta/_journal.json +27 -0
- package/starter/server/db/schema.ts +253 -0
- package/starter/server/plugins/sitemap.ts +11 -0
- package/starter/server/routes/robots.txt.get.ts +12 -0
- package/starter/tsconfig.json +9 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { and, indexTree, inArray, sitePath } from 'tinyzoo'
|
|
2
|
+
import type { CmsEntity, CmsRegistry, CmsSitemapEntry } from 'tinyzoo'
|
|
3
|
+
import { scrubError } from './cmsScrub'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sitemap entries for every public collection with `content.path` (e.g.
|
|
7
|
+
* '/blog/:slug'): published items only, one entry per language the item exists in,
|
|
8
|
+
* each listing its language alternates (for hreflang).
|
|
9
|
+
*/
|
|
10
|
+
export type SitemapEntry = CmsSitemapEntry
|
|
11
|
+
|
|
12
|
+
const MEMO_MS = 60_000
|
|
13
|
+
let memo: { at: number; entries: SitemapEntry[] } | null = null
|
|
14
|
+
|
|
15
|
+
/** Forget the memo (a content change touched an address). */
|
|
16
|
+
export function invalidateSitemap(): void {
|
|
17
|
+
memo = null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* All sitemap entries. Reads only what the addresses need (id, updatedAt and the
|
|
23
|
+
* template's columns — never page bodies), only configured languages, and keeps the
|
|
24
|
+
* result for a minute per instance, so a burst of uncached requests stays cheap.
|
|
25
|
+
*/
|
|
26
|
+
export async function sitemapEntries(db: any, reg: CmsRegistry): Promise<SitemapEntry[]> {
|
|
27
|
+
if (memo && Date.now() - memo.at < MEMO_MS) return memo.entries
|
|
28
|
+
const out: SitemapEntry[] = []
|
|
29
|
+
for (const e of reg.entities) {
|
|
30
|
+
if (!e.content?.public || e.singleton || !e.content.path) continue
|
|
31
|
+
const keys = pathKeys(e.content.path).filter((k) => e.table[k])
|
|
32
|
+
const cols: Record<string, any> = { id: e.table.id, updatedAt: e.table.updatedAt }
|
|
33
|
+
for (const k of keys) cols[k] = e.table[k]
|
|
34
|
+
const rows: any[] = await db.select(cols).from(e.table).where(publishedCond(e)).limit(50_000)
|
|
35
|
+
if (!rows.length) continue
|
|
36
|
+
const translations = await translationsByParent(db, reg, e, rows.map((r) => r.id), keys)
|
|
37
|
+
// A page tree: addresses are the chain of ancestors' address parts (live pages only: publishedCond checks the ancestors).
|
|
38
|
+
const treeIndex = e.tree ? indexTree(await loadTreeNodes(db, reg, e)) : null
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
const versions: { locale: string | null; loc: string; lastmod: Date }[] = []
|
|
41
|
+
if (treeIndex) {
|
|
42
|
+
const lastmods = new Map<string | null, Date>([[reg.locales?.default ?? null, row.updatedAt]])
|
|
43
|
+
for (const tr of translations.get(row.id) ?? []) lastmods.set(tr.locale, tr.updatedAt > row.updatedAt ? tr.updatedAt : row.updatedAt)
|
|
44
|
+
for (const v of treeVersions(reg, e, treeIndex, row.id)) versions.push({ locale: v.locale, loc: v.loc, lastmod: lastmods.get(v.locale) ?? row.updatedAt })
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const defaultLoc = sitePath(reg.locales, e.content.path, reg.locales?.default ?? null, row)
|
|
48
|
+
if (defaultLoc) versions.push({ locale: reg.locales?.default ?? null, loc: defaultLoc, lastmod: row.updatedAt })
|
|
49
|
+
for (const tr of translations.get(row.id) ?? []) {
|
|
50
|
+
// Untranslated fields (e.g. the slug) fall back to the default language.
|
|
51
|
+
const merged = { ...row }
|
|
52
|
+
for (const k of keys) if (tr[k] !== null && tr[k] !== undefined && tr[k] !== '') merged[k] = tr[k]
|
|
53
|
+
const loc = sitePath(reg.locales, e.content.path, tr.locale, merged)
|
|
54
|
+
if (loc) versions.push({ locale: tr.locale, loc, lastmod: tr.updatedAt > row.updatedAt ? tr.updatedAt : row.updatedAt })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const alternates = reg.locales ? versions.map((v) => ({ locale: v.locale!, loc: v.loc })) : []
|
|
58
|
+
for (const v of versions) out.push({ loc: v.loc, locale: v.locale, lastmod: new Date(v.lastmod).toISOString(), alternates })
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
out.push(...fixedPathEntries(reg))
|
|
62
|
+
// A site adds addresses of its own (the news list, pages that come from data): they are
|
|
63
|
+
// kept with the rest for the minute the sitemap is memoised.
|
|
64
|
+
try {
|
|
65
|
+
await useNitroApp().hooks.callHook('cms:sitemap', out)
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error('[cms] cms:sitemap hook failed', scrubError(err))
|
|
69
|
+
}
|
|
70
|
+
const checked = cleanSitemap(out)
|
|
71
|
+
memo = { at: Date.now(), entries: checked }
|
|
72
|
+
return checked
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `cms.sitemap.paths`: fixed addresses; an object lists one page in several languages (hreflang alternates). */
|
|
76
|
+
function fixedPathEntries(reg: CmsRegistry): SitemapEntry[] {
|
|
77
|
+
const configured: (string | Record<string, string>)[] = (useRuntimeConfig().cms as any)?.sitemap?.paths ?? []
|
|
78
|
+
const out: SitemapEntry[] = []
|
|
79
|
+
for (const p of configured) {
|
|
80
|
+
if (typeof p === 'string') {
|
|
81
|
+
out.push({ loc: p, locale: null, lastmod: null, alternates: [] })
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
const versions = Object.entries(p).filter(([l]) => !reg.locales || reg.locales.locales.includes(l))
|
|
85
|
+
const alternates = versions.map(([locale, loc]) => ({ locale, loc }))
|
|
86
|
+
for (const [locale, loc] of versions) out.push({ loc, locale, lastmod: null, alternates })
|
|
87
|
+
}
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Entries from the hook are trusted no further than needed: an address on this site, once. */
|
|
92
|
+
function cleanSitemap(entries: SitemapEntry[]): SitemapEntry[] {
|
|
93
|
+
const seen = new Set<string>()
|
|
94
|
+
const out: SitemapEntry[] = []
|
|
95
|
+
for (const x of entries) {
|
|
96
|
+
if (!x || typeof x.loc !== 'string' || !/^\/(?!\/)[^\s?#]*$/.test(x.loc) || seen.has(x.loc)) continue
|
|
97
|
+
seen.add(x.loc)
|
|
98
|
+
out.push({ loc: x.loc, locale: x.locale ?? null, lastmod: x.lastmod ? new Date(x.lastmod).toISOString() : null, alternates: Array.isArray(x.alternates) ? x.alternates : [] })
|
|
99
|
+
}
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* THE function that says where an entry is on the website: its current address in every
|
|
105
|
+
* language it exists in ({ cs: '/o-nas/tym', en: '/en/about/team' }), from the
|
|
106
|
+
* default-language row and its translations. A page tree gives the nested address (its
|
|
107
|
+
* ancestors' address parts, each language's own, falling back to the default). For a
|
|
108
|
+
* site without languages the one address is under the key ''. Used by the item
|
|
109
|
+
* `paths` of the content API, so a website can link to the same item in another language
|
|
110
|
+
* (a language switcher, hreflang links), and by links that follow their target.
|
|
111
|
+
* Entries that are not at an address are left out.
|
|
112
|
+
*/
|
|
113
|
+
export async function localePaths(db: any, reg: CmsRegistry, e: CmsEntity, ids: string[]): Promise<Map<string, Record<string, string>>> {
|
|
114
|
+
const out = new Map<string, Record<string, string>>()
|
|
115
|
+
if (!e.content?.path || !ids.length) return out
|
|
116
|
+
if (e.tree) {
|
|
117
|
+
const index = indexTree(await loadTreeNodes(db, reg, e))
|
|
118
|
+
for (const id of ids) {
|
|
119
|
+
const paths: Record<string, string> = {}
|
|
120
|
+
for (const v of treeVersions(reg, e, index, id)) paths[v.locale ?? ''] = v.loc
|
|
121
|
+
if (index.has(id)) out.set(id, paths)
|
|
122
|
+
}
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
const keys = pathKeys(e.content.path).filter((k) => e.table[k])
|
|
126
|
+
const cols: Record<string, any> = { id: e.table.id }
|
|
127
|
+
for (const k of keys) cols[k] = e.table[k]
|
|
128
|
+
const rows: any[] = await db.select(cols).from(e.table).where(inArray(e.table.id, ids))
|
|
129
|
+
if (!reg.locales) {
|
|
130
|
+
for (const row of rows) {
|
|
131
|
+
const base = sitePath(null, e.content.path, null, row)
|
|
132
|
+
out.set(row.id, base ? { '': base } : {})
|
|
133
|
+
}
|
|
134
|
+
return out
|
|
135
|
+
}
|
|
136
|
+
const translations = await translationsByParent(db, reg, e, ids, keys)
|
|
137
|
+
for (const row of rows) {
|
|
138
|
+
const paths: Record<string, string> = {}
|
|
139
|
+
const base = sitePath(reg.locales, e.content.path, reg.locales.default, row)
|
|
140
|
+
if (base) paths[reg.locales.default] = base
|
|
141
|
+
for (const tr of translations.get(row.id) ?? []) {
|
|
142
|
+
const merged = { ...row }
|
|
143
|
+
for (const k of keys) if (tr[k] !== null && tr[k] !== undefined && tr[k] !== '') merged[k] = tr[k]
|
|
144
|
+
const loc = sitePath(reg.locales, e.content.path, tr.locale, merged)
|
|
145
|
+
if (loc) paths[tr.locale] = loc
|
|
146
|
+
}
|
|
147
|
+
out.set(row.id, paths)
|
|
148
|
+
}
|
|
149
|
+
return out
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function translationsByParent(db: any, reg: CmsRegistry, e: CmsEntity, ids: string[], keys: string[]): Promise<Map<string, any[]>> {
|
|
153
|
+
const out = new Map<string, any[]>()
|
|
154
|
+
if (!e.localesTable || !ids.length || !reg.locales) return out
|
|
155
|
+
const t = e.localesTable
|
|
156
|
+
const cols: Record<string, any> = { parentId: t.parentId, locale: t.locale, updatedAt: t.updatedAt }
|
|
157
|
+
for (const k of keys) if (e.localized.includes(k)) cols[k] = t[k]
|
|
158
|
+
// Only languages the site still has (a removed language must not reappear).
|
|
159
|
+
const others = reg.locales.locales.filter((l) => l !== reg.locales!.default)
|
|
160
|
+
if (!others.length) return out
|
|
161
|
+
const rows: any[] = await db.select(cols).from(t).where(and(inArray(t.parentId, ids), inArray(t.locale, others)))
|
|
162
|
+
for (const r of rows) out.set(r.parentId, [...(out.get(r.parentId) ?? []), r])
|
|
163
|
+
return out
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The website's absolute base URL for the sitemap: cms.publicUrl. Only in
|
|
168
|
+
* development may it come from the request (never in production, where a forged
|
|
169
|
+
* Host would end up in a publicly cached document).
|
|
170
|
+
*/
|
|
171
|
+
export function siteBase(event: any): string | null {
|
|
172
|
+
const configured = String((useRuntimeConfig().cms as any)?.publicUrl || '').replace(/\/+$/, '')
|
|
173
|
+
if (configured) return configured
|
|
174
|
+
if (import.meta.dev || process.env.NODE_ENV !== 'production') return getRequestURL(event).origin
|
|
175
|
+
return null
|
|
176
|
+
}
|