Skip to content

Instantly share code, notes, and snippets.

@bsrz
Last active September 4, 2023 17:50
Show Gist options
  • Select an option

  • Save bsrz/868d69c5e8b9bb3b1f1b9937eb08fdd3 to your computer and use it in GitHub Desktop.

Select an option

Save bsrz/868d69c5e8b9bb3b1f1b9937eb08fdd3 to your computer and use it in GitHub Desktop.

Getting Started With Publish

extension Theme {
static var hello: Self {
Theme(
htmlFactory: HelloHTMLFactory(),
resourcePaths: ["Resources/ThemeHello/styles.css"]
)
}
}
private struct HelloHTMLFactory<Site: Website>: HTMLFactory {
func makeIndexHTML(for index: Index, context: PublishingContext<Site>) throws -> HTML {
[...]
}
func makeSectionHTML(for section: Section<Site>, context: PublishingContext<Site>) throws -> HTML {
[...]
}
func makeItemHTML(for item: Item<Site>, context: PublishingContext<Site>) throws -> HTML {
[...]
}
func makePageHTML(for page: Page, context: PublishingContext<Site>) throws -> HTML {
[...]
}
func makeTagListHTML(for page: TagListPage, context: PublishingContext<Site>) throws -> HTML? {
[...]
}
func makeTagDetailsHTML(for page: TagDetailsPage, context: PublishingContext<Site>) throws -> HTML? {
[...]
}
}
extension Theme where Site == HelloPublish {
static var hello: Self {
Theme(
htmlFactory: HelloHTMLFactory(),
resourcePaths: ["Resources/ThemeHello/styles.css"]
)
}
}
private struct HelloHTMLFactory: HTMLFactory {
func makeIndexHTML(for index: Index, context: PublishingContext<HelloPublish>) throws -> HTML {
[...]
}
func makeSectionHTML(for section: Section<Site>, context: PublishingContext<HelloPublish>) throws -> HTML {
[...]
}
func makeItemHTML(for item: Item<Site>, context: PublishingContext<HelloPublish>) throws -> HTML {
[...]
}
func makePageHTML(for page: Page, context: PublishingContext<HelloPublish>) throws -> HTML {
[...]
}
func makeTagListHTML(for page: TagListPage, context: PublishingContext<HelloPublish>) throws -> HTML? {
[...]
}
func makeTagDetailsHTML(for page: TagDetailsPage, context: PublishingContext<HelloPublish>) throws -> HTML? {
[...]
}
}
func makeItemHTML(for item: Item<HelloPublish>, context: PublishingContext<HelloPublish>) throws -> HTML {
HTML(
.lang(context.site.language),
.head(for: item, on: context.site),
.body(
.class("item-page"),
.components {
SiteHeader(context: context, selectedSelectionID: item.sectionID)
Wrapper {
Article {
Div(item.content.body).class("content")
Span("Tagged with: ")
ItemTagList(item: item, site: context.site)
}
}
SiteFooter()
}
)
)
}
func makeItemHTML(for item: Item<HelloPublish>, context: PublishingContext<HelloPublish>) throws -> HTML {
HTML(
.lang(context.site.language),
.head(for: item, on: context.site),
.body(
.class("item-page"),
.components {
SiteHeader(context: context, selectedSelectionID: item.sectionID)
Wrapper {
Article {
Div("Originally written on: \(item.date)")
if let updated = item.metadata.updated {
Div("Updated on: \(updated)")
}
Div(item.content.body).class("content")
Span("Tagged with: ")
ItemTagList(item: item, site: context.site)
}
}
SiteFooter()
}
)
)
}
struct HelloPublish: Website {
// ...
struct ItemMetadata: WebsiteItemMetadata {
// Add any site-specific metadata that you want to use here.
}
// ...
}
struct HelloPublish: Website {
// ...
struct ItemMetadata: WebsiteItemMetadata {
var updated: Date?
}
// ...
}
---
date: 2023-05-08 22:36
description: A description of my first post.
tags: first, article
---
# My first post
My first post's text.
---
date: 2023-05-08 22:36
description: A description of my first post.
tags: first, article
updated: 2023-09-04 15:00
---
# My first post
My first post's text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment