Skip to content

Commit

Permalink
builder6 新版官网
Browse files Browse the repository at this point in the history
  • Loading branch information
hotlong committed Oct 17, 2024
1 parent 2d3cb34 commit 732cd87
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 1 deletion.
6 changes: 6 additions & 0 deletions redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
{ "source": "/docs/low-code-academy", "destination": "/docs/low-code-academy/getting-started", "permanent": true},
{ "source": "/docs", "destination": "/docs/deploy/getting-started", "permanent": true},
{ "source": "/cn/steedos/privacy", "destination": "/company/privacy", "permanent": true },
{ "source": "/customer-success-stories", "destination": "/resources/customer-success-stories", "permanent": true },
{ "source": "/customer-success-stories/:documentSlug", "destination": "/resources/customer-success-stories/:documentSlug", "permanent": true },
{ "source": "/cloud", "destination": "/resources/cloud", "permanent": true },
{ "source": "/cloud/:documentSlug", "destination": "/resources/cloud/:documentSlug", "permanent": true },
{ "source": "/solutions", "destination": "/resources/solutions", "permanent": true },
{ "source": "/solutions/:documentSlug", "destination": "/resources/solutions/:documentSlug", "permanent": true },
{ "source": "/register", "destination": "https://id.steedos.cn/", "permanent": true }
]

104 changes: 104 additions & 0 deletions src/b6/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,110 @@ export const getProjectPageByUrl = async (baseId: string, projectId:string, page
return page
}


export const getDocumentById = async (baseId: string, documentId: string) => {

if (!documentId) return null;

const base = await adminBjs.base(baseId);

try {
const document = await base("b6_documents").find(documentId);

console.log('Retrieved page', document.fields._id, document.fields.name);
return document.fields

} catch (e) {
console.error(e);
return null;
}
}

export const getDocumentByUrl = async (baseId: string, blogId: string, documentUrl: string) => {

const base = await adminBjs.base(baseId);

try {
const documents = await base("b6_documents").select({
'filterByFormula': `AND(url === "${documentUrl}", blog_id === "${blogId}")`
}).firstPage();


if (!documents || documents.length === 0) {
return null;
}

console.log('Retrieved document', documents[0].fields._id, documents[0].fields.name);

return documents[0].fields

} catch (e) {
console.error(e);
return null;
}
}

export const getBlogByUrl = async (baseId: string, blogUrl: string) => {

const base = await adminBjs.base(baseId);


try {
const blogs = await base("b6_blogs").select({
fields: ['_id', 'name', 'url', 'parent'],
'filterByFormula': `url === "${blogUrl}"`
}).firstPage();

if (!blogs || blogs.length === 0) {
return null;
}

const blog = blogs[0].fields;

console.log('Retrieved blog', blog._id, blog.name);

// const documents = await base("b6_documents").select({
// 'filterByFormula': `blog_id === "${blog._id}"`
// }).firstPage();

// console.log('Retrieved blog documents', documents.length);

// const docs = documents.map(document => document.fields) as any;
// blog.documents = docs;
// blog.documentsTree = buildTree(docs);
console.log(blog)

return blog

} catch (e) {
console.error(e);
return null;
}
}

export const getBlogDocuments = async (baseId: string, blogId: string) => {

const base = await adminBjs.base(baseId);


try {

const documents = await base("b6_documents").select({
'filterByFormula': `blog_id === "${blogId}"`
}).firstPage();

console.log('Retrieved blog documents', documents.length);

const docs = documents.map(document => document.fields) as any;

return docs

} catch (e) {
console.error(e);
return null;
}
}

export const getComponentByApiName = async (baseId: string, api_name : string) => {

const base = await adminBjs.base(baseId);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/pages/[...slug].js → src/pages/[...slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getStaticPaths = (async () => {

export default function PageDetail({page}){

console.log('PageDetail', page)
// console.log('PageDetail', page)
if (page && page.builder) {
const builderJson = JSON.parse(page.builder)
builderJson.name = page.name;
Expand Down
66 changes: 66 additions & 0 deletions src/pages/resources/[blogSlug]/[documentSlug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useRouter } from 'next/router'

import {NextSeo} from 'next-seo'
import { getProjectById, getBlogByUrl, getDocumentByUrl } from '@/b6/interfaces';
import { RenderBuilderContent } from '@/b6/components/builder6';
import { Markdown } from '@/components/Markdown'

export async function getStaticProps({params, query}) {


const baseId = "spc-66722b5a71056405ab198b56"
const projectId = "ced85241-276f-4d0f-8cfc-84c49d78adee"

const project = await getProjectById(baseId, projectId);
if (!project) return {};

const blog = await getBlogByUrl(baseId, params.blogSlug);
if (!blog) {
return {
notFound: true,
}
}

const document = await getDocumentByUrl(baseId, blog._id, params.documentSlug);

if (!document) {
return {
notFound: true,
}
}

return {
props: {
blog,
document
},
revalidate: parseInt(process.env.NEXT_STATIC_PROPS_REVALIDATE), // In seconds
}
}


export const getStaticPaths = (async () => {
return {
paths: [
],
fallback: "blocking", // false or "blocking"
}
})

export default function PageDetail({blog, document}){

// console.log('post', document)
if (document && document.markdown) {
return (
<div class="max-w-3xl mx-auto pt-16 pb-10 px-4">
<h1 class="text-2xl font-extrabold tracking-tight text-gray-900 md:text-4xl ">{document.name}</h1>
<div class="prose prose-lg py-10">
<Markdown body={document.markdown} className=""></Markdown>
</div>
</div>

);
}

return null;
}
96 changes: 96 additions & 0 deletions src/pages/resources/[blogSlug]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { useRouter } from 'next/router'

import {NextSeo} from 'next-seo'
import { getProjectById, getBlogByUrl, getBlogDocuments } from '@/b6/interfaces';
import { RenderBuilderContent } from '@/b6/components/builder6';
import { Markdown } from '@/components/Markdown'

export async function getStaticProps({params, query}) {


const baseId = "spc-66722b5a71056405ab198b56"
const projectId = "ced85241-276f-4d0f-8cfc-84c49d78adee"

const project = await getProjectById(baseId, projectId);
if (!project) return {};

const blog = await getBlogByUrl(baseId, params.blogSlug);
if (!blog) {
return {
notFound: true,
}
}

const documents = await getBlogDocuments(baseId, blog._id as string);


return {
props: {
blog,
documents
},
revalidate: parseInt(process.env.NEXT_STATIC_PROPS_REVALIDATE), // In seconds
}
}


export const getStaticPaths = (async () => {
return {
paths: [
],
fallback: "blocking", // false or "blocking"
}
})

export default function PageDetail({blog, documents}){

// console.log('blog', blog, documents)
if (blog && documents.length > 0) {
return (
<div className="mx-auto max-w-screen-lg lg:py-16 py-10">
<div className="pb-20">
<h1 className="md:text-4xl text-2xl text-center font-bold text-slate-700 dark:text-slate-200">
{blog.name}
</h1>
{blog.body && (<div className="pt-10">
<Markdown body={blog.body}></Markdown>
</div>)}
</div>

<div className="grid grid-cols-1 gap-y-4 sm:grid-cols-2 sm:gap-x-6 sm:gap-y-10 lg:grid-cols-2 lg:gap-x-8">
{documents?.map((post) => {

const fullSlug = `/resources/${blog.url}/${post.url}`
const imageUrl = post.cover? `https://builder6.steedos.cn` + `/api/files/images/${post.cover}` : null
return (
<div
key={post.slug}
className="group relative flex flex-col overflow-hidden"
>
<div className="aspect-w-5 aspect-h-3 bg-gray-200 group-hover:opacity-75 rounded-lg ">
<img
src={imageUrl}
className="w-full h-full object-center object-cover sm:w-full sm:h-full"
/>
</div>
<div className="flex-1 py-6 space-y-4 flex flex-col">
<h3 className="md:text-2xl text-xl font-medium">
<a href={`${fullSlug}`}>
<span aria-hidden="true" className="text-slate-700 dark:text-slate-200">
{post.name}
</span>
</a>
</h3>
{/* <p className="text-sm text-gray-500">{post.owner__expand?.name}</p> */}
<p className="text-md">{post.summary}</p>
</div>
</div>
)
})}
</div>
</div>
);
}

return null;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 732cd87

Please sign in to comment.