Languages, URLs and SEO
Site languages
Each site has a primary language (primaryLocale) and a list of enabled languages (locales), read from /site. The API serves only enabled languages:
localeoutside the six codesvi,en,es,pt,fr,it→400.- A valid
localethat the site has not enabled →404(exactly like a site that does not exist).
Build your language switcher from locales; do not hard-code it.
What falls back and what does not
| Content | When the translation in the requested locale is missing |
|---|---|
The info block of /site | Uses the primary language version. The locale field in the response tells you which version was actually returned. If staff have never saved the details, info is null. |
| Category names, tag names | Each name falls back to the primary language on its own, and finally to the slug. The locale field says nothing about names. |
Menu labels, menu item url | Each item falls back to the primary language on its own. |
| Posts and pages | No fallback. A post without a translation in locale is not in the list, and opening it by slug returns 404. |
| Per-language custom field values | No fallback: the key is absent from meta. |
What this means for your website:
- The English list may have fewer posts than the Vietnamese list. That is correct behavior.
- The API does not tell you which translations an entry has. When a reader switches language on a post and gets
404, show a message such as "This post is not available in English yet" with a link to the primary language version, instead of a blank error page.
async function loadEntry(slug: string, locale: string, primary: string) {
const res = await fetch(`${API}/entries/${encodeURIComponent(slug)}?locale=${locale}`, { credentials: 'omit' })
if (res.ok) return { entry: (await res.json()).data, missingTranslation: false }
if (res.status === 404 && locale !== primary) {
const fallback = await fetch(`${API}/entries/${encodeURIComponent(slug)}?locale=${primary}`, { credentials: 'omit' })
if (fallback.ok) return { entry: (await fallback.json()).data, missingTranslation: true }
}
if (res.status === 404) return null // render your "not found" page
throw new Error(`CMS ${res.status}`)
}
Slugs and URL structure
- An entry's slug is shared by all languages: the post
le-bon-manghas the same slug invianden. The language goes in your URL (for example/tin-tuc/le-bon-mangand/en/news/le-bon-mang), not in the slug. - Slugs contain only unaccented lowercase letters, digits and single
-(for examplebai-3-bay-phep-bi-tich). You can put a slug straight into a URL without worrying about special characters; still,encodeURIComponentit to be safe. - A category slug and a tag slug can be the same (a category
gioi-treand a taggioi-tre), so keep them in two different URL shapes, for example?category=and?tag=.
Old slugs (renamed paths)
When staff change an entry's slug, the old slug does not return 404 and does not return a 3xx redirect. The API returns 200 with the current entry, and the slug field in the response is the new slug. How to detect it: compare the slug you asked for with data.slug.
- Sites running in the browser (SPA): replace the URL with the new slug without adding history (
history.replaceStateornavigate(…, { replace: true })), so the Back button does not take the reader to the old URL. - Server-rendered sites: return a
301to the URL with the new slug. - Static sites (SSG): you only know the current slug at build time; old slugs are resolved at runtime if your site has a browser-side fallback for slugs that were not pre-built.
const { data: entry } = await res.json()
if (entry.slug !== requestedSlug) {
const url = location.pathname.replace(/[^/]+\/?$/, entry.slug) + location.search + location.hash
history.replaceState(null, '', url)
}
A view signal sent with an old slug still counts for the current entry.
SEO: what the API gives you
| You need | Take it from |
|---|---|
<title>, <meta name="description"> | The entry's seo.title, seo.description (generated by the server if staff leave them empty; seo.auto is then true). |
Share image (og:image) | cover.url, cover.alt. |
Publish date (article:published_time, JSON-LD) | publishedAt (ISO 8601, UTC). |
| The unit's name, address, phone (organization JSON-LD) | info of /site. |
The API does not provide: canonical URLs, a sitemap, the last-modified date, the list of translations of each entry, or a list of static pages. Build canonical URLs yourself according to your site's structure.
Building a sitemap:
- Posts: walk
/entries?locale=…&page=N&limit=100for each language up topageCount. If the site has an "unlisted" content type, posts of that type are not in the general list: also walk the list of each top-level category (a parent category includes the posts of its child categories). - Static pages: there is no path that lists pages. Take them from menu items with
kind: "entry"andentryType: "page", plus the page slugs you and the staff have agreed on (for examplegioi-thieu,lien-he). - Go slowly when walking: see rate limits.
Scheduled posts
A post scheduled for publishing does not appear anywhere before publishedAt. After that time, it appears within about 60 seconds at most (the cache lifetime). If your site is static, the post only appears after the next rebuild.