Skip to content

Commit c542f97

Browse files
authored
Merge pull request #413 from tayloraswift/date-byline
add date byline to doc pages
2 parents 43528de + b9ac8c9 commit c542f97

14 files changed

+91
-22
lines changed

Assets/css/Main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/css/Main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/UnidocRender/Formats/Unidoc.RenderFormat.Assets.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Unidoc.RenderFormat.Assets
1919
/// To reduce cache churn, not all assets are versioned. For example, the fonts and
2020
/// the favicon do not use the version numbers.
2121
@inlinable public static
22-
var version:MajorVersion { .v(36) }
22+
var version:MajorVersion { .v(37) }
2323
}
2424
extension Unidoc.RenderFormat.Assets
2525
{

Sources/UnidocUI/Endpoints/Blog/Unidoc.BlogEndpoint.ArticlePage.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extension Unidoc.BlogEndpoint.ArticlePage:Unidoc.RenderablePage
4141
{
4242
// We need this for the relative links to work.
4343
head[.base] { $0.href = "\(self.location)/" ; $0.target = "_self" }
44+
head[unsafe: .script] { $0.type = "ld+json" } = self.context.structuredData
4445
}
4546
}
4647
extension Unidoc.BlogEndpoint.ArticlePage:Unidoc.StaticPage
@@ -70,6 +71,7 @@ extension Unidoc.BlogEndpoint.ArticlePage:Unidoc.StaticPage
7071
$0[.header, { $0.class = "hero" }]
7172
{
7273
$0[.h1] = self.apex.headline.safe
74+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
7375
}
7476
$0[.div, { $0.class = "docc" }]
7577
{

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.ArticlePage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extension Unidoc.DocsEndpoint.ArticlePage:Unidoc.ApicalPage
6262
}
6363

6464
$0[.h1] = self.apex.headline.safe
65+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
6566
$0[.div] { $0.class = "docc" } = self.cone.overview
6667

6768
if let file:Unidoc.Scalar = self.apex.readme

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.DeclPage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ extension Unidoc.DocsEndpoint.DeclPage:Unidoc.ApicalPage
112112
scalars: self.apex.scope)
113113

114114
$0[.h1] = self.stem.last
115+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
115116
$0[.div] { $0.class = "docc" } = self.cone.overview
116117

117118
if let location:SourceLocation<Unidoc.Scalar> = self.apex.location

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.ModulePage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extension Unidoc.DocsEndpoint.ModulePage:Unidoc.ApicalPage
108108
$0[.h1] = self.name
109109
}
110110

111+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
111112
$0[.div] { $0.class = "docc" } = self.cone.overview
112113

113114
if let readme:Unidoc.Scalar = self.apex.readme

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.PackagePage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extension Unidoc.DocsEndpoint.PackagePage:Unidoc.ApicalPage
8888
}
8989

9090
$0[.h1] = self.title
91+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
9192

9293
guard
9394
let repo:Unidoc.PackageRepo = self.context.repo

Sources/UnidocUI/Endpoints/Docs/Unidoc.DocsEndpoint.ProductPage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extension Unidoc.DocsEndpoint.ProductPage:Unidoc.ApicalPage
5656
}
5757

5858
$0[.h1] = self.apex.symbol
59+
$0[.time] { $0.class = "byline" } = self.context.byline(format.locale)
5960
}
6061

6162
main[.section] { $0.class = "notice canonical" } = self.context.canonical

Sources/UnidocUI/Page contexts/Unidoc.VertexContext (ext).swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
import HTML
2+
import ISO
23
import LexicalPaths
34
import MarkdownABI
45
import MarkdownRendering
56
import Symbols
67
import UnidocRender
8+
import UnixCalendar
79
import URI
810

911
extension Unidoc.VertexContext
1012
{
13+
var structuredData:String
14+
{
15+
if let tagged:Timestamp = self.volume.commit?.date?.timestamp
16+
{
17+
"""
18+
{
19+
"@context": "https://schema.org",
20+
"@type": "Article",
21+
"datePublished": "\(tagged.date)"
22+
}
23+
"""
24+
}
25+
else
26+
{
27+
"""
28+
{
29+
"@context": "https://schema.org",
30+
"@type": "Article"
31+
}
32+
"""
33+
}
34+
}
35+
36+
func byline(_ locale:ISO.Locale) -> Unidoc.Byline?
37+
{
38+
guard
39+
let tagged:Timestamp = self.volume.commit?.date?.timestamp
40+
else
41+
{
42+
return nil
43+
}
44+
45+
return .init(published: tagged, locale: locale)
46+
}
47+
1148
func card(decl id:Unidoc.Scalar) -> Unidoc.DeclCard?
1249
{
1350
guard

Sources/UnidocUI/Page types/Unidoc.VertexPage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extension Unidoc.VertexPage
5454
}
5555

5656
head[unsafe: .script] = format.assets.script(volumes: json)
57+
head[unsafe: .script] { $0.type = "ld+json" } = self.context.structuredData
5758
}
5859

5960
public
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import HTML
2+
import ISO
3+
import UnixCalendar
4+
5+
extension Unidoc
6+
{
7+
struct Byline:Equatable, Sendable
8+
{
9+
let published:Timestamp
10+
let locale:ISO.Locale
11+
12+
init(published:Timestamp, locale:ISO.Locale)
13+
{
14+
self.published = published
15+
self.locale = locale
16+
}
17+
}
18+
}
19+
extension Unidoc.Byline:HTML.OutputStreamable
20+
{
21+
static func |= (time:inout HTML.AttributeEncoder, self:Self)
22+
{
23+
time.datetime = "\(self.published.date)"
24+
}
25+
26+
static func += (time:inout HTML.ContentEncoder, self:Self)
27+
{
28+
time += "Published "
29+
time += self.published.date.short(self.locale)
30+
}
31+
}

Stylesheets/class/hero.less

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@
8383
margin-top: 0.5em;
8484
}
8585

86+
time.byline
87+
{
88+
display: block;
89+
margin: 0.5rem 0;
90+
color: var(--fg-semi);
91+
font-style: italic;
92+
}
93+
time.byline + a.source
94+
{
95+
margin-top: 1rem;
96+
}
8697
a.source + a.source
8798
{
8899
margin-top: 0.5rem;

0 commit comments

Comments
 (0)