@basalf/cms-next 0.0.1 → 0.0.2
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.d.ts +55 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { Metadata } from 'next';
|
|
3
|
+
import { AllPages, Page as Page$1 } from '@basalf/cms';
|
|
4
|
+
export { AllPages, Block, Page as CmsPage, PageSeo, Schemas } from '@basalf/cms';
|
|
5
|
+
|
|
6
|
+
type GetHref = (slug: string, locale: string) => string;
|
|
7
|
+
|
|
8
|
+
type PageProps = {
|
|
9
|
+
/** CMS page slug, e.g. "pricing" or "/pricing" */
|
|
10
|
+
slug: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
/** Canonical URL of this page, used for JSON-LD (mainEntityOfPage). */
|
|
13
|
+
url: string;
|
|
14
|
+
/** Builds the href for a related-page link. Defaults to `/{locale}/{slug}`. */
|
|
15
|
+
getHref?: GetHref;
|
|
16
|
+
/** Image URL used in the Article JSON-LD, if any. */
|
|
17
|
+
imageUrl?: string;
|
|
18
|
+
/** Author used in the Article JSON-LD, if any. */
|
|
19
|
+
author?: {
|
|
20
|
+
name: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Extra classes appended to the outer <article> wrapper. */
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
declare function Page({ slug, locale, url, getHref, imageUrl, author, className, }: PageProps): Promise<react.JSX.Element>;
|
|
27
|
+
|
|
28
|
+
type GetPageMetadataOptions = {
|
|
29
|
+
/** Absolute image URL for openGraph/twitter cards. */
|
|
30
|
+
image?: string;
|
|
31
|
+
};
|
|
32
|
+
declare function getPageMetadata(slug: string, locale: string, options?: GetPageMetadataOptions): Promise<Metadata>;
|
|
33
|
+
|
|
34
|
+
declare function getAllPages(locale?: string): Promise<AllPages>;
|
|
35
|
+
declare function getPageBySlug(slug: string, locale: string): Promise<Page$1 | undefined>;
|
|
36
|
+
|
|
37
|
+
type FaqItem = {
|
|
38
|
+
question: string;
|
|
39
|
+
answer: string;
|
|
40
|
+
};
|
|
41
|
+
type ArticleSchemaProps = {
|
|
42
|
+
page: Page$1;
|
|
43
|
+
url: string;
|
|
44
|
+
imageUrl?: string;
|
|
45
|
+
author?: {
|
|
46
|
+
name: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
declare function ArticleSchema({ page, url, imageUrl, author, }: ArticleSchemaProps): react.JSX.Element | null;
|
|
51
|
+
declare function FaqSchema({ items }: {
|
|
52
|
+
items: FaqItem[];
|
|
53
|
+
}): react.JSX.Element | null;
|
|
54
|
+
|
|
55
|
+
export { ArticleSchema, FaqSchema, type GetHref, type GetPageMetadataOptions, Page, type PageProps, getAllPages, getPageBySlug, getPageMetadata };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"server-only";import{notFound as L}from"next/navigation";import"server-only";import"server-only";import F from"@basalf/cms";var p;function y(){if(p)return p;let e=process.env.BASALF_CMS_TOKEN;if(!e)throw new Error("@basalf/cms-next: missing BASALF_CMS_TOKEN environment variable. Set it server-side only (never expose it to the client bundle).");return p=new F(e),p}async function x(e){let n=await y().getPages();return e?n.filter(r=>r.locale===e):n}async function m(e,t){let n=y(),r=await n.getPages(),a=e.startsWith("/")?e:`/${e}`,s=r.find(l=>l.url===a&&l.locale===t);if(s||(s=r.find(l=>l.url===a)),!!s)return n.getPage(s.pageId)}import"server-only";import E from"next/image";import{jsx as o,jsxs as d}from"react/jsx-runtime";function S(){return o("div",{className:"h-6","aria-hidden":"true"})}function k({content:e}){return o("div",{className:"text-lg text-muted-foreground leading-relaxed [&>p]:mb-3 last:[&>p]:mb-0",dangerouslySetInnerHTML:{__html:e}})}function v({content:e}){return o("div",{className:"text-base text-foreground leading-relaxed [&>p]:mb-3 last:[&>p]:mb-0",dangerouslySetInnerHTML:{__html:e}})}function w({children:e,level:t=2}){return t===3?o("h3",{className:"text-xl font-semibold mt-6 mb-3",children:e}):o("h2",{className:"text-2xl font-semibold mt-8 mb-4",children:e})}function B({list:e}){let t=e.ordered?"ol":"ul",n=e.ordered?"list-decimal":"list-disc";return o(t,{className:`${n} list-inside space-y-2 my-4 ml-2`,children:e.items.map((r,a)=>o("li",{className:"text-foreground [&>p]:inline",dangerouslySetInnerHTML:{__html:r.text}},a))})}function _({image:e}){return d("figure",{className:"my-6",children:[o("div",{className:"relative w-full aspect-video rounded-lg overflow-hidden bg-muted",children:o(E,{src:e.src,alt:e.alt,fill:!0,className:"object-cover"})}),o("figcaption",{className:"text-sm text-muted-foreground mt-2 text-center italic",children:e.alt})]})}function A({items:e}){return o("div",{className:"my-6 space-y-4",children:e.map((t,n)=>d("details",{className:"border border-border rounded-lg overflow-hidden",children:[o("summary",{className:"cursor-pointer p-4 font-medium text-foreground hover:bg-muted/50",children:t.question}),o("div",{className:"p-4 pt-0 text-foreground leading-relaxed",dangerouslySetInnerHTML:{__html:t.answer}})]},n))})}function M({table:e}){return o("div",{className:"my-6 overflow-x-auto rounded-lg border border-border",children:d("table",{className:"w-full text-sm",children:[e.headers&&o("thead",{className:"bg-muted",children:o("tr",{children:e.headers.map((t,n)=>o("th",{className:"border-b border-border px-4 py-2.5 text-left font-medium text-foreground",children:t},n))})}),o("tbody",{children:e.rows.map((t,n)=>o("tr",{className:"border-b border-border last:border-0 even:bg-muted/30",children:t.map((r,a)=>o("td",{className:"px-4 py-2.5 text-foreground",children:r},a))},n))})]})})}function T({urls:e,allPages:t,locale:n,getHref:r}){let a=e.map(s=>t.find(l=>l.url===`/${s}`||l.url===s)).filter(s=>s!==void 0);return a.length===0?null:d("section",{className:"mt-12 pt-8 border-t border-border",children:[o("h2",{className:"text-xl font-semibold mb-4",children:"Related pages"}),o("div",{className:"space-y-4",children:a.map(s=>d("a",{href:r(s.url,s.locale),className:"block rounded-lg border border-border bg-card p-4 shadow-[0_0_0_rgba(0,0,0,0)] transition-all hover:border-info/60 hover:shadow-[0_4px_16px_-4px_hsl(var(--info)/0.25)]",children:[o("h3",{className:"font-medium mt-2",children:s.seo.title}),o("p",{className:"text-sm text-muted-foreground mt-1",children:s.seo.description})]},s.url))})]})}import"server-only";import{jsx as H}from"react/jsx-runtime";function h({page:e,url:t,imageUrl:n,author:r}){let a=e.seo.schemas.find(l=>l.type==="article");if(!a||a.type!=="article")return null;let s={"@context":"https://schema.org","@type":"Article",headline:a.title,description:a.description,datePublished:`${a.date}T00:00:00+00:00`,dateModified:`${a.date}T00:00:00+00:00`,mainEntityOfPage:{"@type":"WebPage","@id":t},keywords:a.keywords.join(", "),wordCount:a.readingTime*200};if(n&&(s.image=n),r){let l={"@type":"Person",name:r.name,url:r.url};s.author=l,s.publisher=l}return H("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(s)}})}function b({items:e}){if(e.length===0)return null;let t={"@context":"https://schema.org","@type":"FAQPage",mainEntity:e.map(n=>({"@type":"Question",name:n.question,acceptedAnswer:{"@type":"Answer",text:n.answer.replace(/<[^>]*>/g,"")}}))};return H("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(t)}})}import{jsx as i,jsxs as q}from"react/jsx-runtime";function G({slice:e}){switch(e.type){case"description":return i(k,{content:e.content});case"text":return i(v,{content:e.content});case"heading":return i(w,{level:e.level,children:e.content});case"list":return i(B,{list:e.content});case"image":return i(_,{image:e.content});case"faq":return i(A,{items:e.content});case"space":return i(S,{});case"table":return i(M,{table:e.content});case"related":return null}}var O=(e,t)=>`/${t}/${e}`;async function R({slug:e,locale:t,url:n,getHref:r=O,imageUrl:a,author:s,className:l}){let g=await m(e,t);if(!g)return L();let{slices:u,seo:P}=g,f=u.find(c=>c.type==="related"),C=f?await x(t):[],N=u.filter(c=>c.type==="faq").flatMap(c=>c.content);return q("article",{className:["mx-auto max-w-2xl px-5 py-8 md:px-6",l].filter(Boolean).join(" "),children:[i(h,{page:g,url:n,imageUrl:a,author:s}),N.length>0&&i(b,{items:N}),q("header",{className:"mb-8",children:[i("h1",{className:"text-3xl md:text-4xl font-bold mb-4",children:P.title}),i("p",{className:"text-lg text-muted-foreground",children:P.description})]}),i("div",{className:"space-y-4",children:u.map((c,I)=>i(G,{slice:c},I))}),f&&i(T,{urls:f.content,allPages:C,locale:t,getHref:r})]})}import"server-only";async function $(e,t,n={}){let r=await m(e,t);if(!r)return{};let{image:a}=n;return{title:r.seo.title,description:r.seo.description,keywords:r.seo.keywords,openGraph:{title:r.seo.title,description:r.seo.description,type:"article",images:a?[a]:void 0},twitter:{card:"summary_large_image",title:r.seo.title,description:r.seo.description,images:a?[a]:void 0}}}export{h as ArticleSchema,b as FaqSchema,R as Page,x as getAllPages,m as getPageBySlug,$ as getPageMetadata};
|