tinyzoo 0.0.0-stage → 0.2.1

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 (392) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +46 -2
  3. package/app/app.config.ts +35 -0
  4. package/app/assets/brand/characters/bright/bird.svg +1 -0
  5. package/app/assets/brand/characters/bright/bunny.svg +1 -0
  6. package/app/assets/brand/characters/bright/elephant.svg +1 -0
  7. package/app/assets/brand/characters/bright/fox.svg +1 -0
  8. package/app/assets/brand/characters/bright/frog.svg +1 -0
  9. package/app/assets/brand/characters/bright/octopus.svg +1 -0
  10. package/app/assets/brand/characters/muted/bee.svg +1 -0
  11. package/app/assets/brand/characters/muted/bird.svg +1 -0
  12. package/app/assets/brand/characters/muted/butterfly.svg +1 -0
  13. package/app/assets/brand/characters/muted/chick.svg +1 -0
  14. package/app/assets/brand/characters/muted/cow.svg +1 -0
  15. package/app/assets/brand/characters/muted/deer.svg +1 -0
  16. package/app/assets/brand/characters/muted/duck.svg +1 -0
  17. package/app/assets/brand/characters/muted/elephant.svg +1 -0
  18. package/app/assets/brand/characters/muted/fox.svg +1 -0
  19. package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
  20. package/app/assets/brand/characters/muted/koala.svg +1 -0
  21. package/app/assets/brand/characters/muted/ladybug.svg +1 -0
  22. package/app/assets/brand/characters/muted/lion.svg +1 -0
  23. package/app/assets/brand/characters/muted/mouse.svg +1 -0
  24. package/app/assets/brand/characters/muted/octopus.svg +1 -0
  25. package/app/assets/brand/characters/muted/owl.svg +1 -0
  26. package/app/assets/brand/characters/muted/panda.svg +1 -0
  27. package/app/assets/brand/characters/muted/penguin.svg +1 -0
  28. package/app/assets/brand/characters/muted/pig.svg +1 -0
  29. package/app/assets/brand/characters/muted/poodle.svg +1 -0
  30. package/app/assets/brand/characters/muted/raccoon.svg +1 -0
  31. package/app/assets/brand/characters/muted/seal.svg +1 -0
  32. package/app/assets/brand/characters/muted/sheep.svg +1 -0
  33. package/app/assets/brand/characters/muted/snail.svg +1 -0
  34. package/app/assets/brand/characters/muted/turtle.svg +1 -0
  35. package/app/assets/brand/characters/muted/whale.svg +1 -0
  36. package/app/assets/brand/logo/favicon.svg +1 -0
  37. package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
  38. package/app/assets/brand/logo/logo-primary.svg +1 -0
  39. package/app/assets/brand/logo/mascot-reversed.svg +1 -0
  40. package/app/assets/brand/logo/mascot.svg +1 -0
  41. package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
  42. package/app/assets/brand/logo/wordmark.svg +1 -0
  43. package/app/assets/css/cms-admin.css +607 -0
  44. package/app/components/CmsBlocks.vue +30 -0
  45. package/app/components/CmsCell.vue +16 -0
  46. package/app/components/CmsCellBadge.vue +18 -0
  47. package/app/components/CmsCellBlocks.vue +9 -0
  48. package/app/components/CmsCellBoolean.vue +12 -0
  49. package/app/components/CmsCellCode.vue +7 -0
  50. package/app/components/CmsCellColor.vue +13 -0
  51. package/app/components/CmsCellDate.vue +10 -0
  52. package/app/components/CmsCellExcerpt.vue +21 -0
  53. package/app/components/CmsCellGallery.vue +10 -0
  54. package/app/components/CmsCellGroup.vue +23 -0
  55. package/app/components/CmsCellNumber.vue +7 -0
  56. package/app/components/CmsCellRelation.vue +8 -0
  57. package/app/components/CmsCellText.vue +12 -0
  58. package/app/components/CmsCellThumb.vue +18 -0
  59. package/app/components/CmsConfirmDialog.vue +55 -0
  60. package/app/components/CmsContent.vue +103 -0
  61. package/app/components/CmsDayPicker.vue +44 -0
  62. package/app/components/CmsEmptyState.vue +35 -0
  63. package/app/components/CmsField.vue +111 -0
  64. package/app/components/CmsFieldBlocks.vue +353 -0
  65. package/app/components/CmsFieldBoolean.vue +8 -0
  66. package/app/components/CmsFieldColor.vue +42 -0
  67. package/app/components/CmsFieldDate.vue +131 -0
  68. package/app/components/CmsFieldGallery.vue +114 -0
  69. package/app/components/CmsFieldGroup.vue +53 -0
  70. package/app/components/CmsFieldMedia.vue +219 -0
  71. package/app/components/CmsFieldNumber.vue +11 -0
  72. package/app/components/CmsFieldRelationMany.vue +54 -0
  73. package/app/components/CmsFieldRelationOne.vue +47 -0
  74. package/app/components/CmsFieldRichText.vue +45 -0
  75. package/app/components/CmsFieldSelect.vue +41 -0
  76. package/app/components/CmsFieldSlug.vue +46 -0
  77. package/app/components/CmsFieldText.vue +75 -0
  78. package/app/components/CmsFormSections.vue +150 -0
  79. package/app/components/CmsHighlight.vue +22 -0
  80. package/app/components/CmsImage.vue +39 -0
  81. package/app/components/CmsLinkPicker.vue +122 -0
  82. package/app/components/CmsLinkTarget.vue +35 -0
  83. package/app/components/CmsListFilters.vue +107 -0
  84. package/app/components/CmsLiveNotice.vue +64 -0
  85. package/app/components/CmsLoadError.vue +24 -0
  86. package/app/components/CmsMascot.vue +10 -0
  87. package/app/components/CmsMediaLibrary.vue +114 -0
  88. package/app/components/CmsMediaPreview.vue +34 -0
  89. package/app/components/CmsMediaThumb.vue +22 -0
  90. package/app/components/CmsMoment.vue +42 -0
  91. package/app/components/CmsNav.vue +39 -0
  92. package/app/components/CmsPage.vue +86 -0
  93. package/app/components/CmsPasswordInput.vue +22 -0
  94. package/app/components/CmsPresence.vue +29 -0
  95. package/app/components/CmsPreviewPanel.vue +131 -0
  96. package/app/components/CmsPublishReview.vue +102 -0
  97. package/app/components/CmsRevisions.vue +195 -0
  98. package/app/components/CmsRichTextEditor.vue +290 -0
  99. package/app/components/CmsSearch.vue +99 -0
  100. package/app/components/CmsSection.vue +20 -0
  101. package/app/components/CmsSingletonForm.vue +283 -0
  102. package/app/components/CmsStatusBadge.vue +21 -0
  103. package/app/components/CmsTime.vue +16 -0
  104. package/app/components/CmsTranslationRef.vue +27 -0
  105. package/app/components/CmsTreeList.vue +453 -0
  106. package/app/components/CmsUnsavedText.vue +34 -0
  107. package/app/components/CmsWordmark.vue +10 -0
  108. package/app/composables/useCmsAdminHead.ts +18 -0
  109. package/app/composables/useCmsCollab.ts +165 -0
  110. package/app/composables/useCmsConfirm.ts +39 -0
  111. package/app/composables/useCmsEntryActions.ts +75 -0
  112. package/app/composables/useCmsFocus.ts +13 -0
  113. package/app/composables/useCmsForm.ts +273 -0
  114. package/app/composables/useCmsI18n.ts +185 -0
  115. package/app/composables/useCmsLinkTargets.ts +84 -0
  116. package/app/composables/useCmsLive.ts +199 -0
  117. package/app/composables/useCmsSearch.ts +62 -0
  118. package/app/composables/useCmsSeo.ts +99 -0
  119. package/app/composables/useCmsSignedIn.ts +24 -0
  120. package/app/composables/useCmsUiLocale.ts +24 -0
  121. package/app/i18n/cs.ts +781 -0
  122. package/app/i18n/de.ts +781 -0
  123. package/app/i18n/en.ts +782 -0
  124. package/app/i18n/types.ts +22 -0
  125. package/app/layouts/admin.vue +224 -0
  126. package/app/layouts/cms-auth.vue +37 -0
  127. package/app/middleware/cms-api-not-a-page.global.ts +10 -0
  128. package/app/middleware/cms-auth.global.ts +16 -0
  129. package/app/pages/admin/[entity]/[id].vue +1109 -0
  130. package/app/pages/admin/[entity]/index.vue +733 -0
  131. package/app/pages/admin/account.vue +117 -0
  132. package/app/pages/admin/forgot.vue +50 -0
  133. package/app/pages/admin/index.vue +184 -0
  134. package/app/pages/admin/invite/[token].vue +73 -0
  135. package/app/pages/admin/login.vue +84 -0
  136. package/app/pages/admin/media.vue +494 -0
  137. package/app/pages/admin/privacy.vue +193 -0
  138. package/app/pages/admin/reset/[token].vue +52 -0
  139. package/app/pages/admin/setup.vue +87 -0
  140. package/app/pages/admin/styleguide.vue +261 -0
  141. package/app/pages/admin/team.vue +258 -0
  142. package/app/plugins/cmsLivePreview.client.ts +20 -0
  143. package/app/plugins/cmsSignedOut.client.ts +31 -0
  144. package/app/utils/cmsBlockType.ts +11 -0
  145. package/app/utils/cmsBrand.ts +38 -0
  146. package/app/utils/cmsDiff.ts +83 -0
  147. package/app/utils/cmsFetch.ts +7 -0
  148. package/app/utils/cmsFocusInvalid.ts +22 -0
  149. package/app/utils/cmsIssues.ts +128 -0
  150. package/app/utils/cmsJson.ts +28 -0
  151. package/app/utils/cmsMedia.ts +63 -0
  152. package/app/utils/cmsSections.ts +154 -0
  153. package/app/utils/cmsTime.ts +41 -0
  154. package/cli/backup.ts +713 -0
  155. package/cli/breaking.ts +174 -0
  156. package/cli/content-migrate.ts +239 -0
  157. package/cli/db.ts +86 -0
  158. package/cli/export.ts +336 -0
  159. package/cli/generate.ts +146 -0
  160. package/cli/import.ts +643 -0
  161. package/cli/index.ts +140 -0
  162. package/cli/links-convert.ts +291 -0
  163. package/cli/seed-engine.ts +705 -0
  164. package/cli/seed.ts +339 -0
  165. package/cli/status.ts +49 -0
  166. package/cli/tar.ts +304 -0
  167. package/cli/transfer.ts +677 -0
  168. package/cli/up.ts +27 -0
  169. package/cli/upgrade.ts +60 -0
  170. package/cli/versions.ts +60 -0
  171. package/forms/components/CmsForm.vue +186 -0
  172. package/forms/index.ts +203 -0
  173. package/forms/messages.ts +104 -0
  174. package/forms/retention.ts +48 -0
  175. package/forms/server/form.get.ts +12 -0
  176. package/forms/server/form.post.ts +109 -0
  177. package/forms/server/formSettings.ts +12 -0
  178. package/forms/server/forms.ts +127 -0
  179. package/module.ts +373 -0
  180. package/nuxt.config.ts +43 -0
  181. package/package.json +98 -3
  182. package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
  183. package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
  184. package/server/api/cms/[entity]/[id].delete.ts +52 -0
  185. package/server/api/cms/[entity]/[id].get.ts +21 -0
  186. package/server/api/cms/[entity]/[id].patch.ts +116 -0
  187. package/server/api/cms/[entity]/_export.get.ts +69 -0
  188. package/server/api/cms/[entity]/_move.post.ts +81 -0
  189. package/server/api/cms/[entity]/_order.post.ts +49 -0
  190. package/server/api/cms/[entity]/_tree.get.ts +41 -0
  191. package/server/api/cms/[entity]/index.get.ts +62 -0
  192. package/server/api/cms/[entity]/index.post.ts +38 -0
  193. package/server/api/cms/[entity]/options.get.ts +55 -0
  194. package/server/api/cms/_auth/accept.post.ts +33 -0
  195. package/server/api/cms/_auth/forgot.post.ts +39 -0
  196. package/server/api/cms/_auth/invite/[token].get.ts +18 -0
  197. package/server/api/cms/_auth/login.post.ts +42 -0
  198. package/server/api/cms/_auth/logout.post.ts +7 -0
  199. package/server/api/cms/_auth/me.get.ts +5 -0
  200. package/server/api/cms/_auth/me.patch.ts +32 -0
  201. package/server/api/cms/_auth/password.post.ts +29 -0
  202. package/server/api/cms/_auth/reset.post.ts +34 -0
  203. package/server/api/cms/_auth/setup.post.ts +46 -0
  204. package/server/api/cms/_auth/status.get.ts +18 -0
  205. package/server/api/cms/_collab/session.get.ts +30 -0
  206. package/server/api/cms/_collab/socket.ts +51 -0
  207. package/server/api/cms/_collab/unsaved.delete.ts +16 -0
  208. package/server/api/cms/_graph.get.ts +20 -0
  209. package/server/api/cms/_links/resolve.post.ts +17 -0
  210. package/server/api/cms/_links.get.ts +81 -0
  211. package/server/api/cms/_live.ts +30 -0
  212. package/server/api/cms/_media/[id]/usage.get.ts +14 -0
  213. package/server/api/cms/_media/[id].delete.ts +29 -0
  214. package/server/api/cms/_media/[id].get.ts +13 -0
  215. package/server/api/cms/_media/[id].patch.ts +64 -0
  216. package/server/api/cms/_media/exists.post.ts +15 -0
  217. package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
  218. package/server/api/cms/_media/index.get.ts +44 -0
  219. package/server/api/cms/_media/index.post.ts +147 -0
  220. package/server/api/cms/_media/raw/[...key].get.ts +85 -0
  221. package/server/api/cms/_media/raw/[...key].head.ts +2 -0
  222. package/server/api/cms/_overview.get.ts +87 -0
  223. package/server/api/cms/_preview.post.ts +17 -0
  224. package/server/api/cms/_privacy/delete.post.ts +14 -0
  225. package/server/api/cms/_privacy/export.post.ts +25 -0
  226. package/server/api/cms/_privacy/lookup.post.ts +27 -0
  227. package/server/api/cms/_search.get.ts +17 -0
  228. package/server/api/cms/_singleton/[name].get.ts +19 -0
  229. package/server/api/cms/_singleton/[name].put.ts +76 -0
  230. package/server/api/cms/_users/[id]/resend.post.ts +25 -0
  231. package/server/api/cms/_users/[id].delete.ts +21 -0
  232. package/server/api/cms/_users/[id].patch.ts +45 -0
  233. package/server/api/cms/_users/index.get.ts +28 -0
  234. package/server/api/cms/_users/index.post.ts +39 -0
  235. package/server/api/content/[entity]/[slug].get.ts +74 -0
  236. package/server/api/content/[entity]/index.get.ts +100 -0
  237. package/server/api/content/_global/[name].get.ts +23 -0
  238. package/server/api/content/_search.get.ts +28 -0
  239. package/server/api/content/_sitemap.get.ts +8 -0
  240. package/server/api/content/_tree/[entity].get.ts +31 -0
  241. package/server/api/content-types.ts.get.ts +17 -0
  242. package/server/api/health/live.get.ts +10 -0
  243. package/server/api/health/ready.get.ts +21 -0
  244. package/server/api/openapi.get.ts +48 -0
  245. package/server/api/openapi.json.get.ts +32 -0
  246. package/server/db/driver.ts +8 -0
  247. package/server/mail/mailer.ts +43 -0
  248. package/server/middleware/cms-0-headers.ts +37 -0
  249. package/server/middleware/cms-0-migrate-gate.ts +14 -0
  250. package/server/middleware/cms-csrf.ts +28 -0
  251. package/server/middleware/cms-limits.ts +20 -0
  252. package/server/middleware/cms-redirects.ts +21 -0
  253. package/server/middleware/cms-session.ts +41 -0
  254. package/server/middleware/cms-z-plugin-access.ts +15 -0
  255. package/server/plugins/cms-0-config-check.ts +35 -0
  256. package/server/plugins/cms-changes.ts +53 -0
  257. package/server/plugins/cms-content-etag.ts +21 -0
  258. package/server/plugins/cms-errors.ts +45 -0
  259. package/server/plugins/cms-migrate.ts +5 -0
  260. package/server/plugins/cms-plugins.ts +17 -0
  261. package/server/plugins/cms-search.ts +12 -0
  262. package/server/plugins/cms-setup-code.ts +15 -0
  263. package/server/routes/sitemap.xml.get.ts +25 -0
  264. package/server/store/redis.ts +95 -0
  265. package/server/store/types.ts +21 -0
  266. package/server/tasks/cms/retention.ts +10 -0
  267. package/server/tasks/cms/scheduled.ts +10 -0
  268. package/server/tasks/cms/search-reindex.ts +12 -0
  269. package/server/utils/cmsAudit.ts +29 -0
  270. package/server/utils/cmsAuth.ts +143 -0
  271. package/server/utils/cmsBlocks.ts +47 -0
  272. package/server/utils/cmsChanges.ts +222 -0
  273. package/server/utils/cmsCollab.ts +286 -0
  274. package/server/utils/cmsCollabServer.ts +451 -0
  275. package/server/utils/cmsCollate.ts +27 -0
  276. package/server/utils/cmsContent.ts +376 -0
  277. package/server/utils/cmsCrud.ts +361 -0
  278. package/server/utils/cmsCsv.ts +24 -0
  279. package/server/utils/cmsDb.ts +23 -0
  280. package/server/utils/cmsDemo.ts +36 -0
  281. package/server/utils/cmsEmails.ts +125 -0
  282. package/server/utils/cmsErrors.ts +40 -0
  283. package/server/utils/cmsFold.ts +17 -0
  284. package/server/utils/cmsImageSizes.ts +51 -0
  285. package/server/utils/cmsJson.ts +6 -0
  286. package/server/utils/cmsLinkAddress.ts +50 -0
  287. package/server/utils/cmsLinks.ts +248 -0
  288. package/server/utils/cmsListQuery.ts +93 -0
  289. package/server/utils/cmsLive.ts +393 -0
  290. package/server/utils/cmsLocales.ts +96 -0
  291. package/server/utils/cmsMail.ts +28 -0
  292. package/server/utils/cmsMediaGc.ts +188 -0
  293. package/server/utils/cmsMediaKeys.ts +62 -0
  294. package/server/utils/cmsMigrate.ts +86 -0
  295. package/server/utils/cmsPreviewDraft.ts +72 -0
  296. package/server/utils/cmsPrivacy.ts +176 -0
  297. package/server/utils/cmsPublished.ts +57 -0
  298. package/server/utils/cmsRange.ts +38 -0
  299. package/server/utils/cmsRateLimit.ts +82 -0
  300. package/server/utils/cmsRedirects.ts +160 -0
  301. package/server/utils/cmsRetention.ts +61 -0
  302. package/server/utils/cmsRevisions.ts +103 -0
  303. package/server/utils/cmsScheduler.ts +45 -0
  304. package/server/utils/cmsScrub.ts +107 -0
  305. package/server/utils/cmsSearch.ts +354 -0
  306. package/server/utils/cmsSession.ts +102 -0
  307. package/server/utils/cmsSetupCode.ts +97 -0
  308. package/server/utils/cmsSitemap.ts +176 -0
  309. package/server/utils/cmsStorage.ts +580 -0
  310. package/server/utils/cmsStore.ts +109 -0
  311. package/server/utils/cmsTiming.ts +14 -0
  312. package/server/utils/cmsTooMany.ts +9 -0
  313. package/server/utils/cmsTranslationWrite.ts +186 -0
  314. package/server/utils/cmsTree.ts +251 -0
  315. package/server/utils/cmsTreeAddress.ts +65 -0
  316. package/server/utils/cmsUpload.ts +228 -0
  317. package/server/utils/cmsWebhooks.ts +104 -0
  318. package/shared/json.ts +11 -0
  319. package/shared/richtext-editor.ts +56 -0
  320. package/shared/richtext-normalize.ts +33 -0
  321. package/shared/richtext-paste.ts +151 -0
  322. package/shared/storage-delivery.ts +53 -0
  323. package/src/blocks.ts +624 -0
  324. package/src/changes.ts +54 -0
  325. package/src/content-shape.ts +340 -0
  326. package/src/deprecate.ts +64 -0
  327. package/src/descriptor.ts +149 -0
  328. package/src/docs.ts +27 -0
  329. package/src/emitter.ts +94 -0
  330. package/src/entity.ts +624 -0
  331. package/src/errorReport.ts +41 -0
  332. package/src/fields.ts +465 -0
  333. package/src/i18n.ts +26 -0
  334. package/src/index.ts +54 -0
  335. package/src/linkref.ts +31 -0
  336. package/src/links.ts +179 -0
  337. package/src/locales.ts +39 -0
  338. package/src/media.ts +48 -0
  339. package/src/migrate.ts +236 -0
  340. package/src/openapi.ts +377 -0
  341. package/src/paths.ts +88 -0
  342. package/src/plugin.ts +505 -0
  343. package/src/presets.ts +230 -0
  344. package/src/richtext.ts +88 -0
  345. package/src/sdk.ts +181 -0
  346. package/src/search.ts +312 -0
  347. package/src/seed.ts +225 -0
  348. package/src/setupCode.ts +30 -0
  349. package/src/system.ts +219 -0
  350. package/src/tree.ts +421 -0
  351. package/src/upgrades.ts +137 -0
  352. package/starter/.env.example +10 -0
  353. package/starter/README.md +65 -0
  354. package/starter/app/app.config.ts +10 -0
  355. package/starter/app/app.vue +12 -0
  356. package/starter/app/assets/css/main.css +15 -0
  357. package/starter/app/components/global/BlockContact.vue +15 -0
  358. package/starter/app/components/global/BlockCta.vue +15 -0
  359. package/starter/app/components/global/BlockHero.vue +23 -0
  360. package/starter/app/components/global/BlockImage.vue +13 -0
  361. package/starter/app/components/global/BlockText.vue +12 -0
  362. package/starter/app/composables/useSite.ts +77 -0
  363. package/starter/app/error.vue +28 -0
  364. package/starter/app/layouts/default.vue +106 -0
  365. package/starter/app/lib/cms-content.ts +152 -0
  366. package/starter/app/pages/[...slug].vue +66 -0
  367. package/starter/app/pages/hledat.vue +59 -0
  368. package/starter/app/pages/index.vue +20 -0
  369. package/starter/cms.config.ts +137 -0
  370. package/starter/compose.yaml +15 -0
  371. package/starter/drizzle.config.ts +8 -0
  372. package/starter/gitignore.txt +8 -0
  373. package/starter/nuxt.config.ts +13 -0
  374. package/starter/package.json +38 -0
  375. package/starter/scripts/typecheck.mjs +38 -0
  376. package/starter/seed/index.ts +297 -0
  377. package/starter/seed/media/about.jpg +0 -0
  378. package/starter/seed/media/hero.jpg +0 -0
  379. package/starter/seed/media/logo.png +0 -0
  380. package/starter/seed/media/news-bread.jpg +0 -0
  381. package/starter/seed/media/news-morning.jpg +0 -0
  382. package/starter/server/db/migrations/0000_init.sql +269 -0
  383. package/starter/server/db/migrations/0001_page_tree.sql +5 -0
  384. package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
  385. package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
  386. package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
  387. package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
  388. package/starter/server/db/migrations/meta/_journal.json +27 -0
  389. package/starter/server/db/schema.ts +253 -0
  390. package/starter/server/plugins/sitemap.ts +11 -0
  391. package/starter/server/routes/robots.txt.get.ts +12 -0
  392. package/starter/tsconfig.json +9 -0
@@ -0,0 +1,185 @@
1
+ import { resolveText, type LocalizedText } from '../../src/i18n'
2
+ import en from '../i18n/en'
3
+ import cs from '../i18n/cs'
4
+ import de from '../i18n/de'
5
+ import type { AdminMessages, MessageKey, PluralMessage } from '../i18n/types'
6
+
7
+ /**
8
+ * Admin interface language (not content localization).
9
+ *
10
+ * Deliberately not @nuxtjs/i18n: the CMS runs inside the host's app, which may
11
+ * have its own i18n setup with its own routes and locales. This stays out of its way.
12
+ *
13
+ * Locale: the `cms_admin_locale` cookie → the browser's Accept-Language →
14
+ * `cms.admin.defaultLocale` (app.config) → the first available locale.
15
+ */
16
+ const catalogs: Record<string, AdminMessages> = { en, cs, de }
17
+ export const CMS_ADMIN_LOCALES: Record<string, string> = { cs: 'Čeština', en: 'English', de: 'Deutsch' }
18
+
19
+ type Params = Record<string, string | number>
20
+
21
+ function lookup(messages: unknown, key: string): string | PluralMessage | undefined {
22
+ let node: any = messages
23
+ for (const part of key.split('.')) node = node?.[part]
24
+ return typeof node === 'string' || (node && typeof node.other === 'string') ? node : undefined
25
+ }
26
+
27
+ function interpolate(text: string, params?: Params): string {
28
+ if (!params) return text
29
+ return text.replace(/\{(\w+)\}/g, (m, name: string) => (name in params ? String(params[name]) : m))
30
+ }
31
+
32
+ /** A plugin's own texts (`defineCmsPlugin({ i18n })`), by plugin and language; the build puts them in the public runtime config. */
33
+ function pluginMessages(): Record<string, Record<string, unknown>> {
34
+ return ((useRuntimeConfig().public.cmsPlugins as any)?.messages ?? {}) as Record<string, Record<string, unknown>>
35
+ }
36
+
37
+ export function useCmsAdminConfig() {
38
+ const appConfig = useAppConfig()
39
+ return computed(() => {
40
+ const admin = ((appConfig.cms as any)?.admin ?? {}) as Record<string, any>
41
+ const locales = ((admin.locales as string[] | undefined) ?? Object.keys(catalogs)).filter((l) => catalogs[l])
42
+ return {
43
+ name: (admin.name as LocalizedText | undefined) ?? 'tinyzoo',
44
+ siteUrl: (admin.siteUrl as string | undefined) ?? '/',
45
+ accent: (admin.accent as string | undefined) ?? 'mono',
46
+ locales: locales.length ? locales : ['en'],
47
+ defaultLocale: (admin.defaultLocale as string | undefined) ?? 'en',
48
+ timeZone: (admin.timeZone as string | undefined) ?? 'Europe/Prague',
49
+ }
50
+ })
51
+ }
52
+
53
+ export function useCmsI18n() {
54
+ const config = useCmsAdminConfig()
55
+ // Read now, in the component's setup: `t()` is also called later (a page title getter, a handler).
56
+ const plugins = pluginMessages()
57
+ const cookie = useCookie<string | null>('cms_admin_locale', { maxAge: 60 * 60 * 24 * 365, sameSite: 'lax', path: '/' })
58
+ const acceptLanguage = import.meta.server ? useRequestHeaders(['accept-language'])['accept-language'] : undefined
59
+
60
+ const locale = useState<string>('cms-admin-locale', () => {
61
+ const { locales, defaultLocale } = config.value
62
+ if (cookie.value && locales.includes(cookie.value)) return cookie.value
63
+ const header = acceptLanguage ?? (import.meta.client ? navigator.languages.join(',') : '')
64
+ for (const part of header.split(',')) {
65
+ const lang = part.split(';')[0]!.trim().toLowerCase().split('-')[0]!
66
+ if (locales.includes(lang)) return lang
67
+ }
68
+ return locales.includes(defaultLocale) ? defaultLocale : locales[0]!
69
+ })
70
+
71
+ function setLocale(next: string) {
72
+ if (!config.value.locales.includes(next)) return
73
+ cookie.value = next
74
+ locale.value = next
75
+ }
76
+
77
+ /** A message of a plugin (`plugins.<name>.<key>`) in a language. */
78
+ function fromPlugin(lang: string, key: string) {
79
+ const [, name, ...rest] = key.split('.')
80
+ return lookup((plugins[name!] as any)?.[lang], rest.join('.'))
81
+ }
82
+
83
+ /**
84
+ * Translate an interface message. Falls back to English, then to the key itself.
85
+ * A plugin's texts are `plugins.<plugin>.<key>` (see `defineCmsPlugin({ i18n })`).
86
+ */
87
+ function t(key: MessageKey | `plugins.${string}`, params?: Params): string {
88
+ const msg = key.startsWith('plugins.')
89
+ ? (fromPlugin(locale.value, key) ?? fromPlugin('en', key))
90
+ : (lookup(catalogs[locale.value], key) ?? lookup(en, key))
91
+ if (msg === undefined) return key
92
+ if (typeof msg === 'string') return interpolate(msg, params)
93
+ const count = Number(params?.count ?? 0)
94
+ const category = new Intl.PluralRules(locale.value).select(count) as keyof PluralMessage
95
+ return interpolate(msg[category] ?? msg.other, { ...params, count: formatNumber(count) })
96
+ }
97
+
98
+ /** Resolve text a developer wrote in cms.config.ts (string or per-locale map). */
99
+ function tl(text: LocalizedText | undefined | null, fallback = ''): string {
100
+ return resolveText(text, locale.value, [config.value.defaultLocale, 'en']) ?? fallback
101
+ }
102
+
103
+ /**
104
+ * A content language's name in the admin's own language, for use inside a sentence
105
+ * ("angličtina", "Englisch", "English") — not the language's own spelling ("English",
106
+ * "Čeština"), which reads as a foreign word in the middle of a sentence. A name the
107
+ * developer wrote for the admin's language wins.
108
+ */
109
+ function languageName(code: string | null | undefined, label?: LocalizedText | null): string {
110
+ if (!code) return ''
111
+ if (label && typeof label === 'object') {
112
+ const own = resolveText(label, locale.value, [])
113
+ if (own && (label[locale.value] || label[locale.value.split('-')[0]!])) return own
114
+ }
115
+ try {
116
+ const name = new Intl.DisplayNames([locale.value], { type: 'language' }).of(code)
117
+ if (name && name.toLowerCase() !== code.toLowerCase()) return name
118
+ }
119
+ catch { /* an odd code: its label */ }
120
+ return resolveText(label, locale.value, [config.value.defaultLocale, 'en']) ?? code.toUpperCase()
121
+ }
122
+
123
+ function formatNumber(n: number): string {
124
+ return new Intl.NumberFormat(locale.value).format(n)
125
+ }
126
+
127
+ /**
128
+ * Date (and time) in the admin's time zone. A fixed zone — not the server's or the
129
+ * browser's — so the server render and the hydrated page agree.
130
+ */
131
+ function formatDate(value: string | number | Date | null | undefined, opts: { time?: boolean } = { time: true }): string {
132
+ if (value === null || value === undefined || value === '') return ''
133
+ const d = value instanceof Date ? value : new Date(value)
134
+ if (Number.isNaN(d.getTime())) return ''
135
+ return new Intl.DateTimeFormat(locale.value, {
136
+ dateStyle: 'medium',
137
+ ...(opts.time ? { timeStyle: 'short' } : {}),
138
+ timeZone: config.value.timeZone,
139
+ }).format(d)
140
+ }
141
+
142
+ /** Any part of a date (`{ month: 'short' }`, `{ timeStyle: 'short' }`…) in the admin's time zone. */
143
+ function formatDateWith(value: string | number | Date | null | undefined, options: Intl.DateTimeFormatOptions): string {
144
+ if (value === null || value === undefined || value === '') return ''
145
+ const d = value instanceof Date ? value : new Date(value)
146
+ if (Number.isNaN(d.getTime())) return ''
147
+ return new Intl.DateTimeFormat(locale.value, { ...options, timeZone: config.value.timeZone }).format(d)
148
+ }
149
+
150
+ /** "3 hours ago" / "před 3 hodinami". Only call on the client (depends on now). */
151
+ function formatRelative(value: string | number | Date): string {
152
+ const d = value instanceof Date ? value : new Date(value)
153
+ const diff = (d.getTime() - Date.now()) / 1000
154
+ const rtf = new Intl.RelativeTimeFormat(locale.value, { numeric: 'auto' })
155
+ const steps: [Intl.RelativeTimeFormatUnit, number][] = [['second', 60], ['minute', 60], ['hour', 24], ['day', 7], ['week', 4.35], ['month', 12], ['year', Infinity]]
156
+ let amount = diff
157
+ for (const [unit, size] of steps) {
158
+ if (Math.abs(amount) < size) return rtf.format(Math.round(amount), unit)
159
+ amount /= size
160
+ }
161
+ return formatDate(d)
162
+ }
163
+
164
+ /** Admin label of a field from the graph: its `.label()`, else the humanized key. */
165
+ function fieldLabel(field: { key: string; meta?: Record<string, any> } | undefined): string {
166
+ if (!field) return ''
167
+ return tl(field.meta?.label) || humanizeKey(field.key)
168
+ }
169
+ const fieldHelp = (field: { meta?: Record<string, any> } | undefined) => tl(field?.meta?.help) || undefined
170
+ /** Plural / singular names of an entity from the graph. */
171
+ const entityLabel = (e: { name: string; label?: any } | undefined) => (e ? tl(e.label, humanizeKey(e.name)) : '')
172
+ const entitySingular = (e: { name: string; label?: any; labelSingular?: any } | undefined) => (e ? tl(e.labelSingular ?? e.label, humanizeKey(e.name)) : '')
173
+
174
+ return {
175
+ locale: readonly(locale), locales: computed(() => config.value.locales), setLocale,
176
+ t, tl, languageName, formatNumber, formatDate, formatDateWith, formatRelative,
177
+ fieldLabel, fieldHelp, entityLabel, entitySingular,
178
+ }
179
+ }
180
+
181
+ /** "publishedAt" → "Published at", "hero_image" → "Hero image". */
182
+ export function humanizeKey(key: string): string {
183
+ const words = key.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').trim()
184
+ return words.charAt(0).toUpperCase() + words.slice(1).toLowerCase()
185
+ }
@@ -0,0 +1,84 @@
1
+ import { isLinkRef } from '../../src/linkref'
2
+
3
+ /**
4
+ * What a stored link reference (`cms:<entity>/<id>`) points at, for the admin: the
5
+ * target's title and address in the language being edited, and whether visitors can
6
+ * follow it (`live`), it waits for the entry to be published (`draft`), the entry is
7
+ * gone or not readable by this person (`missing`: the two are not told apart).
8
+ *
9
+ * Asked for in batches (one request per tick, whatever number of links are on the
10
+ * screen) and kept per language for the visit; picking a page puts it here directly.
11
+ */
12
+ export interface CmsLinkTarget {
13
+ entity: string
14
+ id: string
15
+ title: string
16
+ path: string | null
17
+ state: 'live' | 'draft' | 'missing'
18
+ }
19
+
20
+ const cacheKey = (locale: string | null, ref: string) => `${locale ?? ''}|${ref}`
21
+
22
+ // One queue for the page: refs wanted this tick, sent together.
23
+ let queue = new Map<string, Set<string>>()
24
+ let timer: ReturnType<typeof setTimeout> | undefined
25
+
26
+ export function useCmsLinkTargets() {
27
+ const route = useRoute()
28
+ const targets = useState<Record<string, CmsLinkTarget>>('cms-link-targets', () => ({}))
29
+ /** The content language being edited (null: single-language content). */
30
+ const locale = computed(() => (typeof route.query.locale === 'string' ? route.query.locale : null))
31
+
32
+ function flush() {
33
+ timer = undefined
34
+ const batches = queue
35
+ queue = new Map()
36
+ for (const [loc, refs] of batches) {
37
+ const wanted = [...refs]
38
+ cmsFetch<{ items: Record<string, CmsLinkTarget> }>('/api/cms/_links/resolve', { method: 'POST', body: { refs: wanted, locale: loc || null } })
39
+ .then((res) => {
40
+ const next = { ...targets.value }
41
+ // A ref the server did not answer for stays unknown (shown without details).
42
+ for (const r of wanted) if (res.items[r]) next[cacheKey(loc || null, r)] = res.items[r]!
43
+ targets.value = next
44
+ })
45
+ .catch(() => { /* the link still works; its details just are not shown */ })
46
+ }
47
+ }
48
+
49
+ /** Ask for these references (in the language being edited) unless already known or on the way. */
50
+ function request(refs: string[], forLocale: string | null = locale.value) {
51
+ if (!import.meta.client) return
52
+ const known = targets.value
53
+ const loc = forLocale ?? ''
54
+ const set = queue.get(loc) ?? new Set<string>()
55
+ for (const r of refs) if (isLinkRef(r) && !known[cacheKey(forLocale, r)]) set.add(r)
56
+ if (!set.size) return
57
+ queue.set(loc, set)
58
+ timer ??= setTimeout(flush, 0)
59
+ }
60
+
61
+ /** Remember what is known already (the picker has just shown it). */
62
+ function seed(ref: string, target: CmsLinkTarget, forLocale: string | null = locale.value) {
63
+ targets.value = { ...targets.value, [cacheKey(forLocale, ref)]: target }
64
+ }
65
+
66
+ /** Forget what is known (a changed page may read differently now). */
67
+ function forget() {
68
+ targets.value = {}
69
+ }
70
+
71
+ const find = (ref: string | null | undefined, forLocale: string | null = locale.value) =>
72
+ (ref ? targets.value[cacheKey(forLocale, ref)] ?? null : null)
73
+
74
+ return { locale, request, seed, forget, find, targets }
75
+ }
76
+
77
+ /** The target of one stored link value, reactive: null while unknown or when the value is not a reference. */
78
+ export function useCmsLinkTarget(value: () => string | null | undefined) {
79
+ const { locale, request, find } = useCmsLinkTargets()
80
+ watch(() => [value(), locale.value] as const, ([v, loc]) => {
81
+ if (v && isLinkRef(v)) request([v], loc)
82
+ }, { immediate: true })
83
+ return computed(() => find(value(), locale.value))
84
+ }
@@ -0,0 +1,199 @@
1
+ import type { Ref } from 'vue'
2
+
3
+ /**
4
+ * The admin's realtime connection: one WebSocket per tab (/api/cms/_live), opened
5
+ * on first use, reconnecting with backoff, and re-sending what this tab watches
6
+ * after a reconnect. Server side: server/utils/cmsLive.ts.
7
+ *
8
+ * Realtime is an extra: when the socket cannot connect (a proxy that blocks
9
+ * WebSockets), the admin works exactly as before.
10
+ */
11
+ export interface LivePerson { id: string; name: string; editing: boolean }
12
+ export interface LiveChange {
13
+ type: string
14
+ entity: string
15
+ id: string | null
16
+ locale: string | null
17
+ version: string | null
18
+ by: string | null
19
+ byName: string | null
20
+ at: string
21
+ }
22
+
23
+ interface TopicState {
24
+ people: Ref<LivePerson[]>
25
+ editing: boolean
26
+ listeners: Set<(c: LiveChange) => void>
27
+ users: number
28
+ }
29
+
30
+ let socket: WebSocket | null = null
31
+ let retry = 0
32
+ let retryTimer: ReturnType<typeof setTimeout> | null = null
33
+ /** Has a socket ever opened in this tab (a reconnect means changes may have been missed). */
34
+ let everOpened = false
35
+ /** Failed attempts in a row without ever opening: the server does not offer realtime. */
36
+ let failedInARow = 0
37
+ const topics = new Map<string, TopicState>()
38
+ /** The app's base path, read once in a component's setup (reconnects run outside it). */
39
+ let baseURL = ''
40
+ const connected = ref(false)
41
+
42
+ /** A change notice made up locally after a reconnect: "check whether you missed something". */
43
+ const resync = (): LiveChange => ({ type: 'resync', entity: '', id: null, locale: null, version: null, by: null, byName: null, at: new Date().toISOString() })
44
+
45
+ function send(msg: unknown) {
46
+ if (socket?.readyState === WebSocket.OPEN) socket.send(JSON.stringify(msg))
47
+ }
48
+
49
+ function connect() {
50
+ if (import.meta.server || socket || !topics.size) return
51
+ const url = (location.protocol === 'https:' ? 'wss:' : 'ws:') + '//' + location.host + baseURL + '/api/cms/_live'
52
+ const ws = new WebSocket(url)
53
+ socket = ws
54
+ let opened = false
55
+ ws.addEventListener('open', () => {
56
+ if (socket !== ws) return
57
+ const reconnect = everOpened
58
+ opened = true
59
+ everOpened = true
60
+ retry = 0
61
+ failedInARow = 0
62
+ connected.value = true
63
+ for (const [topic, st] of topics) {
64
+ send({ type: 'watch', topic, editing: st.editing })
65
+ // Whatever was saved while we were away arrived nowhere: ask everyone to check.
66
+ if (reconnect) for (const fn of st.listeners) fn(resync())
67
+ }
68
+ })
69
+ ws.addEventListener('message', (ev) => {
70
+ if (socket !== ws) return
71
+ let msg: any
72
+ try {
73
+ msg = JSON.parse(String(ev.data))
74
+ }
75
+ catch {
76
+ return
77
+ }
78
+ if (msg?.type === 'ping') return send({ type: 'pong' })
79
+ const st = topics.get(msg?.topic)
80
+ if (!st) return
81
+ if (msg.type === 'presence' && Array.isArray(msg.people)) st.people.value = msg.people
82
+ else if (msg.type === 'change' && msg.change) for (const fn of st.listeners) fn(msg.change)
83
+ })
84
+ ws.addEventListener('close', (ev) => {
85
+ // A socket we already replaced or gave up says nothing about the current one.
86
+ if (socket !== ws) return
87
+ socket = null
88
+ connected.value = false
89
+ for (const st of topics.values()) st.people.value = []
90
+ if (!topics.size) return
91
+ if (!opened && ++failedInARow >= 5) return // realtime is not offered here; the admin works without it
92
+ // Signed out / not allowed / too many tabs: do not hammer the server.
93
+ if (ev.code === 1008 || ev.code === 4401 || ev.code === 4429) retry = Math.max(retry, 5)
94
+ const delay = Math.min(30_000, 1000 * 2 ** retry++) * (0.75 + Math.random() / 2)
95
+ retryTimer = setTimeout(() => {
96
+ retryTimer = null
97
+ connect()
98
+ }, delay)
99
+ })
100
+ }
101
+
102
+ function disconnectIfIdle() {
103
+ if (topics.size) return
104
+ if (retryTimer) clearTimeout(retryTimer)
105
+ retryTimer = null
106
+ socket?.close()
107
+ socket = null
108
+ }
109
+
110
+ /**
111
+ * Watch a topic ('list:post', 'entry:post:<id>') for as long as the calling
112
+ * component lives. `people` includes the current user (filter them out for display).
113
+ */
114
+ export function useCmsLiveTopic(topic: string, onChange?: (c: LiveChange) => void) {
115
+ // On the server this module's state would be shared by every request: render
116
+ // without realtime and let the browser connect.
117
+ if (import.meta.server) return { people: ref<LivePerson[]>([]), connected: ref(false), setEditing(_: boolean) {} }
118
+ baseURL = (useRuntimeConfig().app.baseURL || '/').replace(/\/+$/, '')
119
+ let st = topics.get(topic)
120
+ if (!st) {
121
+ st = { people: ref([]), editing: false, listeners: new Set(), users: 0 }
122
+ topics.set(topic, st)
123
+ }
124
+ const state = st
125
+ {
126
+ state.users++
127
+ if (onChange) state.listeners.add(onChange)
128
+ if (socket?.readyState === WebSocket.OPEN && state.users === 1) send({ type: 'watch', topic, editing: state.editing })
129
+ connect()
130
+ onScopeDispose(() => {
131
+ if (onChange) state.listeners.delete(onChange)
132
+ if (--state.users > 0) return
133
+ topics.delete(topic)
134
+ send({ type: 'unwatch', topic })
135
+ disconnectIfIdle()
136
+ })
137
+ }
138
+ return {
139
+ people: state.people,
140
+ connected,
141
+ setEditing(editing: boolean) {
142
+ if (state.editing === editing) return
143
+ state.editing = editing
144
+ send({ type: 'editing', topic, editing })
145
+ },
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Realtime for one open entry (or global): who else is here, and the changes that
151
+ * matter to this tab — someone else's save in the language this tab edits, or a
152
+ * `resync` after a reconnect. The page decides what to do with them (it compares
153
+ * versions after fetching, so nothing typed meanwhile is lost). This tab's own
154
+ * saves, echoed back, are skipped by version. Deletion sets `deleted`.
155
+ */
156
+ export function useCmsEntryLive(opts: {
157
+ entity: string
158
+ id: string
159
+ /** The version this tab has: the entry's, or in a translation the translation's. */
160
+ version: Ref<string | null>
161
+ dirty: Ref<boolean>
162
+ /** True while this tab saves: its own change may arrive before the save's answer. */
163
+ saving: Ref<boolean>
164
+ /** The language this tab edits: null = the entry itself. */
165
+ locale: Ref<string | null>
166
+ onChange: (c: LiveChange) => Promise<void> | void
167
+ }) {
168
+ const { user } = useUserSession()
169
+ const me = computed(() => (user.value as any)?.id as string | undefined)
170
+ const incoming = ref<LiveChange | null>(null)
171
+ const deleted = ref<LiveChange | null>(null)
172
+
173
+ const { people, setEditing } = useCmsLiveTopic(`entry:${opts.entity}:${opts.id}`, async (c) => {
174
+ if (c.type === 'entry.deleted') {
175
+ deleted.value = c
176
+ return
177
+ }
178
+ if (opts.saving.value) await new Promise<void>((resolve) => {
179
+ const stop = watch(opts.saving, (s) => {
180
+ if (s) return
181
+ stop()
182
+ resolve()
183
+ })
184
+ })
185
+ if (c.type !== 'resync') {
186
+ // Translations are separate: only the language this tab edits matters.
187
+ const isTranslation = c.type.startsWith('translation.')
188
+ if (isTranslation ? c.locale !== opts.locale.value : opts.locale.value !== null) return
189
+ // Our own save, echoed back.
190
+ if (c.version && c.version === opts.version.value) return
191
+ }
192
+ await opts.onChange(c)
193
+ })
194
+
195
+ watch(opts.dirty, (d) => setEditing(d), { immediate: true })
196
+
197
+ const others = computed(() => people.value.filter((p) => p.id !== me.value))
198
+ return { others, incoming, deleted }
199
+ }
@@ -0,0 +1,62 @@
1
+ // The website search, ready to use: published entries of every public collection
2
+ // with an address, in the page's language, best first, each with its address and a
3
+ // snippet around the words found (GET /api/content/_search).
4
+ //
5
+ // const route = useRoute()
6
+ // const { items, total, pending } = await useCmsSearch(() => String(route.query.q ?? ''), { locale: lang })
7
+ // <NuxtLink v-for="r in items" :to="r.path"><CmsHighlight :text="r.title" :ranges="r.titleHighlights" /></NuxtLink>
8
+ //
9
+ // Rendered on the server for the first query (a search page works without JavaScript
10
+ // and can be linked to); asks again whenever the query or the language changes.
11
+
12
+ export interface CmsSearchItem {
13
+ entity: string
14
+ id: string
15
+ title: string
16
+ /** Where the words are in the title, as [start, end) character ranges. */
17
+ titleHighlights: [number, number][]
18
+ /** A sentence or two of the entry's text around the first word found ('' when only the title matched). */
19
+ excerpt: string
20
+ highlights: [number, number][]
21
+ /** The entry's address on the website, in the searched language. */
22
+ path: string | null
23
+ locale: string | null
24
+ updatedAt: string
25
+ }
26
+
27
+ export interface CmsSearchResult { query: string; items: CmsSearchItem[]; total: number }
28
+
29
+ export async function useCmsSearch(
30
+ query: MaybeRefOrGetter<string>,
31
+ opts: {
32
+ locale?: MaybeRefOrGetter<string | null | undefined>
33
+ /** Most results (1–50, default 10). */
34
+ limit?: number
35
+ /** Only these collections, e.g. ['page', 'news']. */
36
+ entities?: string[]
37
+ } = {},
38
+ ) {
39
+ const q = computed(() => String(toValue(query) ?? '').trim())
40
+ const locale = computed(() => toValue(opts.locale) || undefined)
41
+ const params = computed(() => ({
42
+ q: q.value,
43
+ ...(locale.value ? { locale: locale.value } : {}),
44
+ ...(opts.limit ? { limit: opts.limit } : {}),
45
+ ...(opts.entities?.length ? { entity: opts.entities.join(',') } : {}),
46
+ }))
47
+ // Asks again whenever the query or the language changes (a query under two letters
48
+ // is answered at once with nothing, without touching the database).
49
+ const { data, pending, error } = await useFetch<CmsSearchResult>('/api/content/_search', {
50
+ query: params,
51
+ key: computed(() => `cms-search:${JSON.stringify(params.value)}`),
52
+ default: () => ({ query: '', items: [], total: 0 }),
53
+ })
54
+ return {
55
+ items: computed(() => data.value?.items ?? []),
56
+ total: computed(() => data.value?.total ?? 0),
57
+ /** The query the shown results are for. */
58
+ searched: computed(() => data.value?.query ?? ''),
59
+ pending,
60
+ error,
61
+ }
62
+ }
@@ -0,0 +1,99 @@
1
+ // The page's head from a CMS item: title, description, sharing image, language and the
2
+ // address of the page in every language (canonical, hreflang, og:url, og:locale), from
3
+ // the seo() fields (metaTitle, metaDescription, ogImage) and the item's `paths`, with
4
+ // sensible fallbacks.
5
+ //
6
+ // const { data: post } = await useFetch(`/api/content/post/${slug}`)
7
+ // useCmsSeo(() => post.value?.item, { siteName: 'Triatlon Tábor' })
8
+ // useCmsSeo(page, { siteName, fallback: settings }) // the site's own description and image when the page has none
9
+ // useCmsSeo(page, { siteName, defaultLocale: 'cs' }) // hreflang="x-default" points at the Czech version
10
+ //
11
+ // Addresses are absolute (canonical and hreflang must be): they start with the site's
12
+ // address, `cms.publicUrl` (NUXT_CMS_PUBLIC_URL; in development the address you open the
13
+ // site at). Without either — a production site that has not set it — the address tags
14
+ // are left out rather than guessed from a request header.
15
+ export function useCmsSeo(
16
+ item: MaybeRefOrGetter<Record<string, any> | null | undefined>,
17
+ opts: {
18
+ siteName?: string; titleField?: string; descriptionField?: string; imageField?: string
19
+ /** Site-wide defaults (e.g. the site settings with seo()): their metaDescription and ogImage. */
20
+ fallback?: MaybeRefOrGetter<{ metaDescription?: string | null; ogImage?: { url?: string } | null } | null | undefined>
21
+ /** The site's default language: its version is hreflang="x-default" (the first version when not given). */
22
+ defaultLocale?: string
23
+ /** How an address from the content API is written on the website: the home page of a site is `/`, not `/home`. */
24
+ path?: (path: string, locale: string) => string
25
+ /** og:locale per language code when the guess (cs → cs_CZ) is not what you want: { en: 'en_GB' }. */
26
+ ogLocales?: Record<string, string>
27
+ } = {},
28
+ ) {
29
+ const it = computed(() => toValue(item) ?? null)
30
+ const title = computed(() => {
31
+ const i = it.value
32
+ const own = i?.metaTitle || (opts.titleField ? i?.[opts.titleField] : i?.title) || ''
33
+ return own && opts.siteName ? `${own} · ${opts.siteName}` : own || opts.siteName || ''
34
+ })
35
+ const site = computed(() => toValue(opts.fallback) ?? null)
36
+ const description = computed(() => it.value?.metaDescription || (opts.descriptionField ? it.value?.[opts.descriptionField] : '') || site.value?.metaDescription || undefined)
37
+ const image = computed(() => it.value?.ogImage?.url || (opts.imageField ? it.value?.[opts.imageField]?.url : undefined) || site.value?.ogImage?.url || undefined)
38
+
39
+ // The site's own address, worked out on the server (where the configuration is) and
40
+ // carried to the browser, so client-side navigation writes the same tags.
41
+ const base = useState<string>('cms-seo-base', () => {
42
+ if (!import.meta.server) return ''
43
+ const configured = String((useRuntimeConfig() as any).cms?.publicUrl || '').replace(/\/+$/, '')
44
+ return configured || (import.meta.dev ? useRequestURL().origin : '')
45
+ })
46
+ // This item in every language it exists in: { cs: '/o-nas', en: '/en/about' }.
47
+ const versions = computed(() => {
48
+ const paths = it.value?.paths
49
+ if (!paths || typeof paths !== 'object') return [] as { locale: string; href: string }[]
50
+ return Object.entries(paths as Record<string, string>)
51
+ .filter(([, p]) => typeof p === 'string' && p.startsWith('/'))
52
+ .map(([locale, p]) => ({ locale, href: (opts.path ? opts.path(p, locale) : p) }))
53
+ })
54
+ const locale = computed<string | undefined>(() => it.value?.locale ?? undefined)
55
+ const canonical = computed(() => {
56
+ if (!base.value) return undefined
57
+ // A page shown in a language it has no version in (the default language's text) belongs to the version it is.
58
+ const own = versions.value.find((v) => v.locale === locale.value) ?? versions.value.find((v) => v.locale === opts.defaultLocale) ?? versions.value[0]
59
+ return own ? base.value + own.href : undefined
60
+ })
61
+ const ogLocale = (code: string) => {
62
+ const lang = code.split(/[-_]/)[0]!.toLowerCase()
63
+ return opts.ogLocales?.[code] ?? opts.ogLocales?.[lang] ?? (code.includes('-') || code.includes('_') ? code.replace('-', '_') : OG_TERRITORY[lang] ?? lang)
64
+ }
65
+
66
+ useSeoMeta({
67
+ title: () => title.value || undefined,
68
+ ogTitle: () => title.value || undefined,
69
+ description: () => description.value,
70
+ ogDescription: () => description.value,
71
+ ogImage: () => image.value,
72
+ ogUrl: () => canonical.value,
73
+ ogLocale: () => (locale.value ? ogLocale(locale.value) : undefined),
74
+ ogLocaleAlternate: () => (locale.value ? versions.value.filter((v) => v.locale !== locale.value).map((v) => ogLocale(v.locale)) : undefined),
75
+ twitterCard: () => (image.value ? 'summary_large_image' : 'summary'),
76
+ })
77
+ useHead({
78
+ htmlAttrs: { lang: () => locale.value },
79
+ link: () => {
80
+ if (!base.value) return []
81
+ // Each shape spelled out: unhead's link types are a union keyed on `rel`, which a loose { rel: string } does not satisfy.
82
+ const links: ({ rel: 'canonical'; href: string } | { rel: 'alternate'; hreflang: string; href: string })[] = []
83
+ if (canonical.value) links.push({ rel: 'canonical', href: canonical.value })
84
+ // The versions point at each other (itself included); one version alone has nothing to say.
85
+ if (versions.value.length > 1) {
86
+ for (const v of versions.value) links.push({ rel: 'alternate', hreflang: v.locale, href: base.value + v.href })
87
+ const def = versions.value.find((v) => v.locale === opts.defaultLocale) ?? versions.value[0]!
88
+ links.push({ rel: 'alternate', hreflang: 'x-default', href: base.value + def.href })
89
+ }
90
+ return links
91
+ },
92
+ })
93
+ return { title, description, image, canonical }
94
+ }
95
+
96
+ /** og:locale wants language_TERRITORY; the common languages' usual territory (a guess for the rest is the bare language). */
97
+ const OG_TERRITORY: Record<string, string> = {
98
+ cs: 'cs_CZ', sk: 'sk_SK', en: 'en_US', de: 'de_DE', pl: 'pl_PL', fr: 'fr_FR', es: 'es_ES', it: 'it_IT', nl: 'nl_NL', pt: 'pt_PT', hu: 'hu_HU', uk: 'uk_UA',
99
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * After an auth endpoint signed someone in: refresh the client session, switch to
3
+ * their saved interface language, and continue to `redirect` (only same-site admin
4
+ * paths — never an absolute URL from the query string).
5
+ */
6
+ export function useCmsSignedIn() {
7
+ const { fetch: refreshSession } = useUserSession()
8
+ const { setLocale } = useCmsI18n()
9
+ const route = useRoute()
10
+ return async (user?: { locale?: string | null }) => {
11
+ await refreshSession()
12
+ if (user?.locale) setLocale(user.locale)
13
+ const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
14
+ const safe = redirect.startsWith('/admin') && !redirect.startsWith('//') ? redirect : '/admin'
15
+ // A full page load, not an in-app jump: the first admin page then arrives rendered
16
+ // by the server, icons from cms.config.ts included (in-app they would pop in late).
17
+ await navigateTo(safe, { external: true })
18
+ }
19
+ }
20
+
21
+ /** The message to show for a failed auth request: the server's, or a generic one. */
22
+ export function cmsErrorMessage(err: any, fallback: string): string {
23
+ return err?.data?.statusMessage || err?.statusMessage || fallback
24
+ }