对于许多开发者来说,拥有一个属于自己的博客是分享知识、记录成长的最佳方式。比如说我在掘金上发的文章,刀乐都让掘金赚了,搭建一个博客有助于提升我们程序员的影响力。
今天,我们将介绍一个解决方案:使用 Sanity.io 这个 Headless CMS,结合前端框架 SolidStart,来构建一个属于你自己的博客。
先看看Demo
什么是 Sanity.io?
Sanity.io 是一个现代化的、可定制的 Headless 内容管理系统(CMS)。就是说它提供可视化管理端来管理我们数据库的东西。这意味着你可以使用任何你喜欢的前端技术(如 Next.js, React, Vue 等)来构建你的网站或应用,并通过 API 从 Sanity 获取内容。
Sanity 的主要优势包括:
- 高度灵活的内容建模:你可以通过简单的 JavaScript 对象来定义你想要的内容结构(Schema),完全掌控你的数据模型,如下我定义了一个作者表
import {
defineField, defineType} from 'sanity'
export default defineType({
name: 'author',
title: 'Author',
type: 'document',
fields: [
defineField({
name: 'name',
title: 'Name',
type: 'string',
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'name',
maxLength: 96,
},
}),
defineField({
name: 'image',
title: 'Image',
type: 'image',
options: {
hotspot: true,
},
}),
defineField({
name: 'bio',
title: 'Bio',
type: 'array',
of: [
{
title: 'Block',
type: 'block',
styles: [{
title: 'Normal', value: 'normal'}],
lists: [],