MijoCoder

How to create a blog with Publish

Official readme is a bit spartan, but it's enough to get started: README.md (v0.8.0)

The first thing that probably everyone will want to do is show the body of a section.

For example, almost every blog has an "About" page, and that page has some title and a body. The default theme "Foundation" only shows the tile and a list of items.

The solution is to copy Publish/Sources/Publish/API/Theme+Foundation.swift into a new file MyBlog/Sources/MyBlog/Theme+MyBlog.swift and override relevant parts. For example: override method makeSectionHTML(Section<Site>, PublishingContext<Site>). It's enough to replace H1(section.title) with Div(section.body).class("content").

The second thing I changed is the conversion of multiline blockquotes into HTML.

The old logic removes newline characters and joins all lines. So, for example, the following markup:

> One
> Two
> Three

Is turned into: <blockquote><p>One Two Three</p></blockquote> instead of <blockquote><p>One</p><p>Two</p><p>Three</p></blockquote>

To change this behavior, we need to modify the Ink package. To do that, we need to reference the local Publish package, and then in local Publish, we need to reference the local Ink package because the remote dependencies are read-only. (Change .package(name: "Ink", url: "https://github.com/johnsundell/ink.git", from: "0.2.0"), to .package(path: "/path/to/Ink"))

Tagged with: