SteamPress

Language Build Status MIT License

SteamPress:使用 Swift 编写的博客引擎和平台。

steampress-coreSteamPress 的核心引擎。它使用协议来定义数据库存储,因此可以与任何 Vapor 数据库提供程序一起使用。

该博客既可以作为您站点的根目录(即出现在 https://www.acme.org),也可以出现在子路径中(即 https://www.acme.org/blog/)。

特性

如何使用

首先,将包添加到你的 Package.swift 依赖项中

dependencies: [

// ...

.package(url: "https://github.com/iankoex/steampress-core.git", from: "2.0.8"),

],

然后将其作为依赖项添加到你的应用程序目标中

.target(name: "App",

dependencies: [

// ...

.product(name: "SteamPressCore", package: "steampress-core"),

])

configure.swift 中,导入该包

import SteamPressCore

接下来,配置你首选的数据库,在此示例中我们使用 postgres

if let databaseURL = Environment.get("DATABASE_URL") {
    try app.databases.use(.postgres(url: databaseURL), as: .psql)
}

接下来,设置 SteamPressLifecycleHandler、presenter 和 repository

let feedInfo = FeedInformation(
    title: "The SteamPress Blog",
    description: "SteamPress is an open-source blogging engine written for Vapor in Swift",
    copyright: "Released under the MIT licence",
    imageURL: "https://user-images.githubusercontent.com/9938337/29742058-ed41dcc0-8a6f-11e7-9cfc-680501cdfb97.png"
)
let steamPressConfig = SteamPressConfiguration(feedInformation: feedInfo, postsPerPage: 4, enableAuthorPages: true, enableTagPages: true)
let steamPressLifecycle = SteamPressLifecycleHandler(configuration: steamPressConfig)
app.lifecycle.use(steamPressLifecycle)
    
// Presenters
app.steampress.application.presenters.register(.blog) { req in
    ViewBlogPresenter(req)
}
app.steampress.application.presenters.register(.admin) { req in
    ViewBlogAdminPresenter(req)
}
    
// Repositories
app.steampress.application.repositories.register(.blogTag) { req in
    FluentTagRepository(req)
}
app.steampress.application.repositories.register(.blogPost) { req in
    FluentPostRepository(req)
}
app.steampress.application.repositories.register(.blogUser) { req in
    FluentUserRepository(req)
}

配置

您应该将 SP_WEBSITE_URL 环境变量设置为站点的根地址,例如 https://www.steampress.io。 这用于设置整个 SteamPress 中的各种参数。 您还可以将 SP_BLOG_PATH 环境变量设置为您希望博客所在的路径,例如 blog。 网站因此将在 https://www.steampress.io/blog 上可用。 管理页面将在 steampress 路径下找到。 根据你的 SP_BLOG_PATH,管理页面可以在 https://www.steampress.io/blog/steampress 上找到。

登录

首次访问管理页面时,你需要创建一个所有者帐户。

评论

SteamPress 目前支持使用 Disqus 作为评论引擎。 要使用 Disqus,请使用环境变量 BLOG_DISQUS_NAME 设置为你的 Disqus 站点名称来启动应用程序。(你可以从你的 Disqus 管理面板获取你的 Disqus 站点名称)

这会将其传递给 Blog index (blog.leaf)、blog posts (blogpost.leaf)、author page (profile.leaf) 和 tag page (tag.leaf) 的 Leaf 模板,因此你可以在需要时包含它。 如果你想手动设置评论,你可以自己完成,只需包含你的提供程序所需的文件即可。 这主要是为了为 示例站点 提供简单的配置。

Open Graph Twitter Card 支持

SteamPress 支持 Open Graph 和 Twitter Cards。 博客文章页面上下文将以 ISO 8601 格式传递创建日期和上次编辑日期(如果适用),用于 Open Graph 文章支持,参数为 createdDateNumericlastEditedDateNumeric

博客文章页面还将传递许多其他有用的参数,用于 Open Graph 和 Twitter Cards。 请参阅下面的 blogpost.leaf 部分。

可以通过 BLOG_SITE_TWITTER_HANDLE 环境变量配置站点的 Twitter handle(不带 @ 的站点 Twitter handle)。 如果设置了,它将被注入到公共页面中,如下所述。 这是用于 Twitter Cards 的 twitter:site 标签。

Google Analytics 支持

SteamPress 使你可以轻松地将 Google Analytics 集成到你的博客中。 只需使用环境变量 BLOG_GOOGLE_ANALYTICS_IDENTIFIER 设置为你的 Google Analytics 标识符来启动应用程序。(你可以从 Google Analytics 控制台获取你的标识符,它看起来像 UA-12345678-1)

这会将 googleAnalyticsIdentifier 参数传递到 site 变量中的所有公共页面,你可以包含该参数,然后使用 示例站点的 javascript 进行集成。

Atom/RSS 支持

SteamPress 自动提供用于注册 RSS 阅读器的端点,可以使用 RSS 2.0 或 Atom 1.0。 这些端点可以在博客的 atom.xmlrss.xml 路径中找到; 例如,如果你的博客位于 https://www.example.com/blog,则 atom feed 将出现在 https://wwww.example.com/blog/atom.xml。 这些默认情况下会工作,但是你可能想要配置一些字段。 这些通过传递给提供程序的 FeedInformation 参数进行配置。 配置选项是

搜索支持

SteamPress 内置了博客搜索。 它将在你的博客路径下注册一个路由 /search,你可以将查询发送到该路由,使用 term 键来搜索博客。

API

SteamPress 还包含一个 API,用于访问某些可能有用的内容。 当前的端点是

我们正在努力公开更多端点。