-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ps1
More file actions
162 lines (143 loc) · 5.91 KB
/
config.ps1
File metadata and controls
162 lines (143 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#requires -Module Organize, Turtle
if (-not $global:site) {
$global:site = [Ordered]@{}
}
$site = $global:site
# Add Google analytics id.
$site.AnalyticsID = 'G-YJ8BNN14KL'
#region Populate At Protocol Data
if (-not $global:site.AtData.Tables) {
$global:site.AtData = [Data.DataSet]::new()
$ssd = $global:site.AtData.Tables.Add("site.standard.document")
$ssd.Columns.AddRange(@(
[Data.DataColumn]::new('title', [string], '', 'Attribute')
[Data.DataColumn]::new('path', [string], '', 'Attribute')
[Data.DataColumn]::new('site', [string], '', 'Attribute')
[Data.DataColumn]::new('atUri', [string], '', 'Attribute')
[Data.DataColumn]::new('publishedAt', [DateTime], '', 'Attribute')
[Data.DataColumn]::new('tags', [string], '', 'Attribute')
))
Get-ChildItem -Path ./document -Recurse -File |
Get-Content -Raw |
ConvertFrom-Json |
Foreach-Object {
$in = $_
$newRow = $ssd.NewRow()
$newRow.title = $in.title
$newRow.path = $in.path
$newRow.site = $in.site
$newRow.atUri = $in.atUri
if ($in.publishedAt) {
$newRow.publishedAt = $in.publishedAt
}
$newRow.tags = $in.tags
$ssd.Rows.Add($newRow)
}
$ssp = $global:site.AtData.Tables.Add("site.standard.publication")
$ssp.Columns.AddRange(@(
[Data.DataColumn]::new('name', [string], '', 'Attribute')
[Data.DataColumn]::new('atUri', [string], '', 'Attribute')
[Data.DataColumn]::new('description', [string], '', 'Attribute')
[Data.DataColumn]::new('url', [string], '', 'Attribute')
$optOut = [Data.DataColumn]::new('optout', [bool], '', 'Attribute')
$optOut.DefaultValue = $false
$optOut
))
Get-ChildItem -Path ./publication -Recurse -File |
Get-Content -Raw |
ConvertFrom-Json |
Foreach-Object {
$in = $_
$newRow = $ssp.NewRow()
$newRow.name = $in.name
$newRow.url = $in.url
$newRow.description = $in.description
$newRow.atUri = $in.atUri
if ($in.optout) {
$newRow.optout = $true
}
$ssp.Rows.Add($newRow)
}
$ssi = $global:site.AtData.Tables.Add("site.standard.index")
$ssi.Columns.AddRange(@(
[Data.DataColumn]::new('title', [string], '', 'Attribute')
[Data.DataColumn]::new('url', [string], '', 'Attribute')
[Data.DataColumn]::new('publishedAt', [DateTime], '', 'Attribute')
[Data.DataColumn]::new('atUri', [string], '', 'Attribute')
[Data.DataColumn]::new('site', [string], '', 'Attribute')
[Data.DataColumn]::new('name', [string], '', 'Attribute')
[Data.DataColumn]::new('tags', [string], '', 'Attribute')
[Data.DataColumn]::new('description', [string], '', 'Attribute')
))
foreach ($pub in $ssp.Select("optout = false")) {
foreach ($doc in $ssd.Select("site = '$($pub.aturi)'")) {
$finalUrl = ($pub.url -replace '/$'), ($doc.path -replace '^/') -join '/'
$newRow = $ssi.NewRow()
$newRow.title = $doc.title
$newRow.name = $pub.name
$newRow.atUri = $doc.atUri
$newRow.url = $finalUrl
$newRow.site = $doc.site
$newRow.description = $pub.description
$newRow.tags = $doc.tags
if ($doc.publishedAt) {
$newRow.publishedAt = $doc.publishedAt
}
$ssi.Rows.add($newRow)
}
}
}
#endregion Populate At Protocol Data
Write-Host -ForegroundColor Cyan "Organizing index of $($global:site.AtData.tables['site.standard.index'].Rows.Count) rows"
$organized = $global:site.AtData.tables['site.standard.index'].Select('
PublishedAt IS NOT NULL','PublishedAt DESC'
) |
organize 'PublishedAt.Year/Month/Day'
Write-Host -ForegroundColor Cyan "Organized index into $($organized.Output.Count) buckets"
$indexHtmlTemplate = (Get-Command ./index.html.ps1 -CommandType ExternalScript).ScriptBlock
foreach ($year in $organized.Output.Keys) {
Write-Host -ForegroundColor Cyan "Year: $year"
$yearPath = Join-Path -Path $PSScriptRoot $year
$yearIndex = @()
foreach ($month in $organized.Output[$year].Keys) {
$monthPath = Join-Path -Path $yearPath $(
"{0:d2}" -f ($month -as [int])
)
$monthIndex = @()
Write-Host -ForegroundColor Cyan "Month: $month"
foreach ($day in $organized.Output[$year][$month].Keys) {
if (-not $day) { continue }
$dayPath = Join-Path $monthPath $(
"{0:d2}" -f ($day -as [int])
)
$dayIndex = $organized.Output[$year][$month][$day] |
Select-Object $global:site.AtData.tables['site.standard.index'].Columns.ColumnName
$monthIndex += $dayIndex
New-Item -ItemType File -Path (
Join-Path $dayPath 'index.json'
) -Value (
$dayIndex | ConvertTo-Json -Depth 2
) -Force
New-Item -ItemType File -Path (
Join-Path $dayPath 'index.html.ps1'
) -Value "$indexHtmlTemplate" -Force
}
New-Item -ItemType File -Path (
Join-Path $monthPath 'index.json'
) -Value (
$monthIndex | ConvertTo-Json -Depth 2
) -Force
New-Item -ItemType File -Path (
Join-Path $monthPath 'index.html.ps1'
) -Value "$indexHtmlTemplate" -Force
$yearIndex += $monthIndex
}
New-Item -ItemType File -Path (
Join-Path $yearPath 'index.json'
) -Value (
$yearIndex | ConvertTo-Json -Depth 2
) -Force
New-Item -ItemType File -Path (
Join-Path $yearPath 'index.html.ps1'
) -Value "$indexHtmlTemplate" -Force
}