-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add atom feed to the blog #46
Open
bioball
wants to merge
1
commit into
apple:main
Choose a base branch
from
bioball:rss-feed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
:date: 2024-04-29 | ||
:author: Dan Chao | ||
:author-url: https://github.com/bioball | ||
|
||
= Pkl Evolution | ||
|
||
:use-link-attrs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Bare minimum typings needed for our bespoke feed extension. | ||
import * as Vinyl from "vinyl" | ||
|
||
export type NavigationBuiltEvent = { | ||
contentCatalog: ContentCatalog; | ||
playbook: Playbook; | ||
uiCatalog: UiCatalog; | ||
navigationCatalog: {}, | ||
siteCatalog: SiteCatalog; | ||
}; | ||
|
||
export type Register = (context: Context) => any; | ||
export type Register = (this: Context) => any; | ||
|
||
interface SiteCatalog { | ||
addFile(file: { contents: Buffer; out: { path: string } }); | ||
} | ||
|
||
interface ContentCatalog { | ||
getComponent(id: string): Component | ||
getComponentVeresion(id: string, version: string): Component | ||
getComponents(): Component[] | ||
getComponentsSortedBy(property: string): Component[] | ||
getFiles(): File[] | ||
getPages(filter?: (file: File) => Boolean): File[] | ||
getSiteStartPage(): File?; | ||
addFile(file: any): void; | ||
/** | ||
* Attempts to resolve a string contextual page ID spec to a file in the catalog. | ||
* | ||
* Parses the specified contextual page ID spec into a page ID object, then attempts to lookup a | ||
* file with this page ID in the catalog. If a component is specified, but not a version, the | ||
* latest version of the component stored in the catalog is used. If a page cannot be resolved, | ||
* the search is attempted again for an "alias". If neither a page or alias can be resolved, the | ||
* function returns undefined. If the spec does not match the page ID syntax, this function throws | ||
* an error. | ||
* | ||
* @param spec - The contextual page ID spec (e.g., version@component:module:topic/page.adoc). | ||
* @param ctx - The context to use to qualified the contextual page ID. | ||
* | ||
* @returns {File} The virtual file to which the contextual page ID spec refers, or undefined if the | ||
* file cannot be resolved. | ||
*/ | ||
resolvePage(id: string, ctx: object = {}): File?; | ||
} | ||
|
||
interface ContentCatalogModel { | ||
|
||
} | ||
|
||
interface File extends Vinyl { | ||
asciidoc: Asciidoc? | ||
} | ||
|
||
interface Asciidoc { | ||
attributes: Record<string, string>; | ||
doctitle?: string; | ||
navtitle?: string; | ||
xreftext?: string; | ||
} | ||
|
||
interface Component { | ||
latest: { | ||
displayVersion: string | ||
title: string | ||
version: string | ||
name: string | ||
} | ||
title: string | ||
url: string | ||
} | ||
|
||
interface Logger { | ||
info(msg: string): void; | ||
} | ||
|
||
interface Context { | ||
getLogger(id: string): Logger; | ||
on(event: "navigationBuilt", handler: (event: NavigationBuiltEvent) => any): void; | ||
} | ||
|
||
interface Playbook { | ||
antora: { generator: string; }; | ||
asciidoc: { attributes: Record<string, string>; extensions: string[] }; | ||
output: { dir: string; clean: boolean } | ||
} | ||
|
||
interface UiCatalog { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component, ContentCatalog, ContentCatalogModel } from "@antora/antora"; | ||
|
||
export interface SiteUiModel { | ||
title: string; | ||
ui: { | ||
url: string; | ||
defaultLayout: string; | ||
}; | ||
homeUrl: string; | ||
components: { [string]: Component } | ||
} | ||
|
||
export interface BaseUiModel { | ||
antoraVersion: string; | ||
contentCatalog: ContentCatalogModel; | ||
env: Record<string, string>; | ||
site: SiteUiModel; | ||
} | ||
|
||
export interface UiModel extends BaseUiModel { | ||
siteRootPath: string; | ||
uiRootPath: string; | ||
} | ||
|
||
export function buildSiteUiModel(playbook, contentCatalog): SiteUiModel; | ||
|
||
export function buildUiModel(baseUiMode, file, contentCatalog, navigationCatalog): UiModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Register } from "@antora/antora"; | ||
import { Feed, FeedOptions } from "feed"; | ||
import path from "path"; | ||
|
||
// @ts-ignore copyright line is not required | ||
const baseFeedOptions: FeedOptions = { | ||
title: "Pkl Blog", | ||
description: "Blog site from the maintainers of the Pkl configuration language", | ||
id: "https://pkl-lang.org/blog/index.html", | ||
link: "https://pkl-lang.org/blog/index.html", | ||
language: "en-US", | ||
favicon: "https://pkl-lang.org/_/img/favicon.svg", | ||
generator: "Pkl Blog" | ||
} | ||
|
||
const register: Register = (context) => { | ||
context.on("navigationBuilt", function ({ contentCatalog, playbook, siteCatalog }) { | ||
const feed = new Feed(baseFeedOptions); | ||
let lastUpdated: Date = new Date(0); | ||
for (let page of contentCatalog.getPages((it) => it.basename !== "index.adoc" && it.asciidoc?.attributes["page-component-name"] === "blog")) { | ||
const asciidoc = page.asciidoc!!; | ||
const date = new Date(asciidoc.attributes.date); | ||
if (date > lastUpdated) { | ||
lastUpdated = date; | ||
} | ||
feed.addItem({ | ||
title: asciidoc.doctitle!!, | ||
id: asciidoc.attributes.docname, | ||
// @ts-ignore | ||
link: path.join(playbook.site.url, page.out.path), | ||
date: date, | ||
published: date, | ||
author: [ | ||
{ | ||
name: asciidoc.attributes.author, | ||
link: asciidoc.attributes["author-url"] | ||
} | ||
], | ||
content: page.contents?.toString(), | ||
}) | ||
} | ||
feed.options.updated = lastUpdated; | ||
siteCatalog.addFile({ | ||
contents: Buffer.from(feed.atom1()), | ||
out: { | ||
path: 'blog/feed.xml' | ||
} | ||
}) | ||
}); | ||
}; | ||
|
||
module.exports = { register }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,11 @@ code { | |
.blog-byline { | ||
color: #5c6370; | ||
} | ||
|
||
.blog-feed { | ||
margin-top: 5em; | ||
} | ||
|
||
.blog-feed img { | ||
width: 1em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: we can't substitute these attributes in the byline, because it breaks when we embed that byline into
index.adoc
.Also, these attributes must be placed before the header.