Ola Rubaj a62addbfbb
Dev how-to pages (#890)
Related to #878

## Changes
How-to docs pages:

- /howto/index: home page for guides
- /howto/analytics: "How to add Google Analytics?"
- /howto/seo: "How to customize page metadata for SEO?"
- /howto/sitemap: "How to build a sitemap?"
- /howto/blog: "How to add a simple blog?"
  - blog index page
  - blog layout
  - comments -> link to the page below
- /howto/comments: "How to add user comments?"
- /howto/markdown: "How to add markdown-based content pages?"
- /howto/drd: "How to create data-rich documents with charts and tables?"
2023-05-19 11:15:52 +02:00

1.6 KiB

How to add a simple blog?

Setup

The following example uses components imported from the @flowershow/core package. If you want to follow along install it too:

npm i @flowershow/core

Create home page for your blogs

Add the following code to the Next.js page that is going to be your blog home page, e.g. to /pages/blog/index.tsx:

import { BlogsList, SimpleLayout } from "@flowershow/core";

// pass a list of blogs, home page title and home page description, e.g. from `getStaticProps`
export default function BlogIndex({ blogs, title, description }) {
    return (
        <SimpleLayout title={title} description={description}>
            <BlogsList blogs={blogs} />
        </SimpleLayout>
    );
}

BlogsList component has the following API:

interface BlogsListProps {
	blogs: Blog;
}

interface Blog {
	title: string;
	date: string;
	urlPath: string;
	description?: string;
	authors?: Array<string>;
	tags?: Array<string>;	
}

Create blog post pages

Add the following code to your blog pages, e.g. to /pages/blog/[...slug].tsx:

import { BlogLayout } from "@flowershow/core";

export default BlogPost({ content, title, date, authors }) {
	return (
		<BlogLayout title={title} date={date} authors={authors}
			{content}
		</BlogLayout>
	)	
}

BlogLayout component has the following API:

interface BlogLayoutProps {
	title?: string;
	date?: string;
	authors?: Array<Author>;
}

interface Author {
	name: string;
	avatar: string; // avatar image path
	urlPath?: string; // author page
}