Next.js static site management with Outstatic

Content management systems (CMS) such as WordPress and Drupal have made the process of sharing digital content on the web less technical. They largely eliminate the need to learn server-side or database programming.

Static CMSs specifically allow you to create and manage digital content for static sites.

In this short guide, How to Download and Install the iOS 16 Public Beta we'll explore Outstatic, a relatively new static CMS package. We'll cover how it works, how to bulk remove image backgrounds on the iPhone, how to install and configure Outstatic for your Next.js application, and how to start creating and fetching content.

Jump ahead:

  • What is external static electricity? How outstatic works

  • Get Started with Outstatic and Next.js Create a GitHub OAuth Application Add Outstatic to Next.js

  • Static content managementCreate collectionCreate document: Markdown editor gets data

To follow this tutorial, How to Turn 5G On or Off on the iPhone and Whether You Should Use It You should be familiar with Next.js static site generation and have some basic knowledge of Git and GitHub.

What is external static electricity?

Outstatic is a static CMS package created for Next.js applications. It will be available to developers in late 2022.

The tool enables you to create, edit and save content, display file extensions in the Files app on iPhone and iPad and then automatically commit to your repository and deploy to your live website. Outstatic is fast, doesn't require any database configuration, and includes a dashboard to dynamically create and manage your content.

Numerous use cases for the framework include blogging, 5 easy ways to change the sound of an alarm clock on an iPhone, portfolio sites, news sites, and documentation sites for managing and presenting projects.

How outstatic works

Outstatic uses the collection document pattern to store data. 6 Ways to Turn Off Location on iPhone You can think of a collection as a table in a traditional database, and a document is a single record in that table.

Every Outstatic project is linked to your GitHub account and GitHub repository. Everything you create is then mapped to a remote GitHub repository and converted to a markdown file.

You can then manage your content directly on the Outstatic dashboard or get them in your Next.js app on demand.

Getting started with Outstatic and Next.js

To explore the power of Outstatic, how to message yourself on WhatsApp from iPhone, Android, Web, and desktop we'll create a simple blog site to showcase our recent writing. How to Use the Compass App on iPhone: A Detailed Guide When everything is done, let's take a sneak peek at what our app will look like:

Let's start by creating a new Next.js application:

npx create-next-app outstatic-blog

As mentioned earlier, Outstatic requires a connection to GitHub to function. How to Add a Google Search Bar to Android and iPhone Home Screens So we have to push our project to GitHub before we can start creating collections and documentation.

转到 GitHub,创建一个新的存储库,如何在 iPhone 上的邮件应用程序中设置电子邮件提醒并将我们刚刚创建的新 Next.js 应用程序推送到这个存储库。如果您不熟悉此过程,可以参考GitHub 中的有用指南。

创建 GitHub OAuth 应用程序

您的 Outstatic 仪表板是您可以管理所有内容的地方。如何免费在 AirPods 外壳上刻上拟我表情、表情符号或文字要授权访问此仪表板和写入访问您的 GitHub 存储库,您需要创建一个新的 GitHub OAuth 应用程序。如何将 iPhone 上的主屏幕布局重置为默认设置这将允许 Outstatic 远程创建集合和文档。

首先向 GitHub 注册您的新 OAuth 应用程序。SOS 仅在 iPhone 上意味着什么以及修复它的 10 种方法如果您直接按照本教程进行操作,那么在注册过程中,请确保您输入的信息与下面显示的信息相符:

在新的 GitHub OAuth 应用程序页面中,如何在 iPhone 上像专业人士一样设置和使用 Gmail您应该会看到显示的应用程序客户端 ID。您还应该看到“生成新的客户端密码”按钮。单击此按钮可生成新密码。

完成后,将新生成的值与客户端 ID 一起复制,如何按名字或姓氏对 iPhone 和 iPad 上的联系人进行排序暂时将其保存在安全的地方。

将 Outstatic 添加到 Next.js

下一步是在我们的 Next.js 应用程序中安装 Outstatic 框架。如何在 Apple Music 上制作播放列表并在 iPhone 上对其进行排序我们可以使用以下命令执行此操作:

npm install outstatic

# OR

yarn add outstatic

我们还需要安装以下 ProseMirror 依赖项,在 iPhone 上向 WhatsApp 添加联系人的 5 种方法因为它们是创建 Outstatic 内容编辑器所必需的:

npm install prosemirror-dropcursor prosemirror-gapcursor prosemirror-history

# OR

yarn add prosemirror-dropcursor prosemirror-gapcursor prosemirror-history

接下来,在 Next.js 的默认目录中,如何在 iPhone 和 iPad 上使用 Apple Music Sing 进行卡拉 OK创建一个新文件并将以下内容粘贴到其中:/pagesoutstatic/[[...ost]].tsx

import 'outstatic/outstatic.css'

import { Outstatic, OstSSP } from 'outstatic'

export default Outstatic

export const getServerSideProps = OstSSP

上面的代码导出了Outstatic一个OstSSP函数。如何在 Android 和 iOS 上恢复最近删除的联系人该OstSSP功能负责创建 Outstatic 内容管理仪表板以及将在其上发生的所有其他与服务器相关的操作。

此外,如何清除 iPhone 上的键盘历史记录在 default 中创建一个新文件并将以下代码粘贴到该文件中:outstatic/[[...ost]].tsx/pages/api

import { OutstaticApi } from 'outstatic'

export default OutstaticApi

上面的代码是 Outstatic 与Next.js API 功能集成的地方,允许它异步获取创建的内容。

最后,在您的项目根文件夹中,创建一个新文件并将以下代码粘贴到其中:.env

OST_GITHUB_ID=YOUR_GITHUB_OAUTH_APP_ID

OST_GITHUB_SECRET=YOUR_GITHUB_OAUTH_APP_SECRET

OST_TOKEN_SECRET=A_RANDOM_TOKEN

OST_REPO_SLUG=YOUR_GITHUB_REPOSITORY_SLUG

让我们仔细看看上面代码中设置的环境变量:

  • OST_GITHUB_ID— 来自我们之前创建的 GitHub OAuth 应用程序的客户端 ID

  • OST_GITHUB_SECRET— 我们之前生成的客户端密码

  • OST_TOKEN_SECRET— 至少包含 32 个字符的随机字符串您可以使用免费在线服务轻松生成一个

  • OST_REPO_SLUG— 你的 GitHub 仓库名称

我们现在都完成了!使用命令运行 Next.js 应用程序npm run dev并导航到http://localhost:3000/outstatic。你会看到这样的输出:

使用您的 GitHub 帐户登录以确认授权,您应该被重定向到您的 Outstatic 内容仪表板,如下所示:

静态内容管理

我们可以使用 Outstatic 内容编辑器直接创建新集合并管理这些集合中的所有内容。现在让我们探讨如何创建和管理 Outstatic 集合和文档。

创建集合

让我们为我们的博客帖子创建一个新集合。单击 Outstatic 仪表板上显示的“新收藏”按钮。然后,在集合名称字段中键入“帖子”,如下所示,然后单击“保存”按钮:

创建文档:Markdown 编辑器

Outstatic 具有用于创建文档的交互式编辑器。在这个编辑器中,你可以编写 Markdown 代码,并立即生成相应的输出。此外,您可以轻松设置所选元素的格式、导入图像等:

现在我们已经走到这一步了,您可以自己探索编辑器了。尝试为我们的收藏创建一些新文档Posts,添加封面照片和描述,并确保将它们的状态设置为“已发布”。

获取数据

如果您使用该git pull命令拉取远程更改,您将看到 Outstatic 已创建一个新文件夹。在这个文件夹中,我们创建的所有集合和文档都存在,并转换为 Markdown 文件。outstatic/content

Outstatic 包支持以下方法:

  • getDocuments()获取所有文档的方法

  • getDocumentBySlug()通过 slug 获取单个文档的方法

然后,我们可以利用这些方法和原生 Next.jsgetStaticProps或getServerSideProps方法来为我们的应用程序获取创建的内容。

要继续,请将文件的内容替换为以下内容:pages/index.js

import { getDocuments } from "outstatic/server";

import Link from "next/link";

const Index = ({ posts }) => {

return (

<>

<div className="container">

<h1>Welcome to my Blog!</h1>

<div className="row">

{posts.map((post) => (

<Link href={"/blog/" + post.slug} key={post.publishedAt}>

<div className="card">

<img

className="card-img"

src={post.coverImage}

alt={post.title}

/>

<div className="card-body">

<h2>{post.title}</h2>

<p>{post.description}</p>

<small className="author">By: {post.author.name}</small>

</div>

</div>

</Link>

))}

</div>

</div>

</>

);

};

export default Index;

export const getStaticProps = async () => {

const posts = getDocuments("posts", [

"title",

"publishedAt",

"slug",

"coverImage",

"description",

"author",

]);

return {

props: { posts },

};

};

在这里,我们使用该方法来获取我们所有帖子的文档。然后我们将返回的数据作为 prop 传递给我们的页面组件。getDocuments()

之后,我们通过返回的数据进行映射,并为每次迭代显示一张博客卡片。每张博客卡片都显示帖子的封面图片、标题、描述和作者姓名。我们还将每张博客卡片链接到一个显示博客内容的动态页面。

要为您的 Next.js 应用程序添加一点美感,请将文件中的内容替换为以下代码:styles/global.css

html,

body {

padding: 0;

margin: 0;

font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,

Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;

}

.container {

padding: 30px;

}

.row {

display: flex;

justify-content: space-between;

}

.card {

border: 1px solid;

max-width: 450px;

}

.card-body {

padding: 10px;

}

.card-img {

width: 100%;

border-bottom: 1px solid #282828;

}

.author {

color: #4c4c4c;

font-weight: 400;

}

使用以下命令运行应用程序:

npm run dev

然后,您应该会在浏览器中看到类似于以下内容的输出:

对于我们的博客信息页面,在现有文件夹中创建一个新文件并将以下代码粘贴到其中:blog/[slug].js/pages

import { getDocuments, getDocumentBySlug } from "outstatic/server";

const BlogSingle = ({ post }) => {

return (

<div>

<div className="container">

<img

className="card-img"

src={post.coverImage}

alt={post.title}

style={ { maxHeight: "450px" }}

/>

<div className="card-body">

<h2 style={ { margin: "10px 0" }}>{post.title}</h2>

<small className="author">By: {post.author.name}</small>

<p style={ { marginTop: "5vh" }}>{post.content}</p>

</div>

</div>

</div>

);

};

export default BlogSingle;

export async function getStaticPaths() {

const posts = getDocuments("posts", ["slug"]);

const paths = posts.map((post) => ({

params: { slug: post.slug },

}));

return {

paths,

fallback: false,

};

}

export const getStaticProps = async ({ params }) => {

const slug = params.slug;

const post = getDocumentBySlug("posts", slug, [

"title",

"slug",

"coverImage",

"author",

"content",

]);

return {

props: { post },

};

};

这是此文件中发生的事情的概要。首先,我们使用 Next.js方法和 Outstatic方法检索所有文档并为它们生成动态路径。getStaticPaths()getDocuments()

此外,我们将 Next.js方法与 Outstatic 方法结合使用,以通过传递的 slug 检索文档的内容。在此之后,我们将返回的数据作为 prop 传递并显示在我们的页面上。getStaticProps()getDocumentBySlug()

如果我们现在运行我们的应用程序,我们应该看到一切正常,如下面的 GIF 所示:

结论

Outstatic 是一个新兴的 Next.js 静态 CMS。本教程通过使用它来构建一个简单的博客站点来演示它是如何工作的。Outstatic 是一个相当新的图书馆,不断改进,似乎有一个充满希望的未来。

Guess you like

Origin blog.csdn.net/weixin_47967031/article/details/130013617