Skip to content

Commit ed6a42b

Browse files
committed
Created a way to generate post tags filter urls on site
Signed-off-by: David Söderlund <[email protected]>
1 parent 0940d17 commit ed6a42b

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

docs/_layouts/tags.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
layout: default
3+
---
4+
5+
<div>
6+
<h1>Articles tagged with "{{ page.tag-name }}"</h1>
7+
<ul style='padding-top: 16px;'>
8+
9+
{% for post in site.posts %}
10+
{% if post.tags contains page.tag-name %}
11+
<li><a href="{{ post.url }}">{{ post.title }}</a>, published {{ post.date | date: "%Y-%m-%d" }}</li>
12+
{% endif %}
13+
{% endfor %}
14+
</ul>
15+
</div>

jekyll.build.ps1

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ Content here
109109
}
110110

111111
task importImages {
112-
if($IsLinux -eq $true) {
112+
if ($IsLinux -eq $true) {
113113
$screenshotdir = Get-Item ~/Pictures
114114
$prefixToRemove = 'Screenshot from '
115115
}
116-
elseif($IsWindows -eq $true) {
116+
elseif ($IsWindows -eq $true) {
117117
$screenshotdir = Get-Item ~/OneDrive/Pictures/Screenshots
118118
$prefixToRemove = 'Skärmbild '
119119
}
120-
if($screenshotdir -ne $null) {
120+
if ($screenshotdir -ne $null) {
121121
Get-ChildItem $screenshotdir | Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-$cutoffMinutes) } | ForEach-Object {
122-
$newname = $_.Name.Replace($prefixToRemove,'').Replace(' ','-').ToLower()
122+
$newname = $_.Name.Replace($prefixToRemove, '').Replace(' ', '-').ToLower()
123123
Write-Host "Copying $($_.FullName) to $rootdir/docs/assets/$newname"
124124
Copy-Item $_.FullName "$rootdir/docs/assets/$newname"
125125
}
@@ -128,5 +128,39 @@ task importImages {
128128
Write-Host "Couldn't import any screenshots, check the path [$screenshotdir]"
129129
}
130130
}
131+
132+
task posttags {
133+
push-location $rootdir/docs
134+
Remove-Item tags -Recurse -ErrorAction SilentlyContinue | Out-Null
135+
New-Item tags -ItemType Directory | Out-Null
136+
$frontMatterPattern = '(?ms)^---\s*\r?\n(.*?)\r?\n---\s*\r?\n'
137+
138+
$alltags = @()
139+
foreach ($file in gci _posts) {
140+
$content = Get-Content $file -raw
141+
if ($content -match $frontMatterPattern) {
142+
foreach ($line in $matches[1] -split [System.Environment]::NewLine) {
143+
$line -split ':', 2 | % {
144+
$parts = $line -split ':', 2
145+
if ($parts.Count -eq 2) {
146+
$key = $parts[0].Trim()
147+
if ($key -eq 'tags') {
148+
$value = $parts[1].Trim() -split ' '
149+
$alltags += $value.ToLower()
150+
}
151+
}
152+
}
153+
}
154+
}
155+
}
156+
$alltags = $alltags | Sort-Object -Unique
157+
Write-Host "All tags: "
158+
Write-Host $alltags
159+
$alltags | Sort-Object -Unique | % {
160+
"---`nlayout: tags`ntag-name: $_`n---" | Out-File -Path "tags/$_.md"
161+
}
162+
163+
}
164+
task generateTags posttags
131165
task copyImages importImages
132-
task . proofread, serve, surf
166+
task . proofread, generateTags, serve, surf

0 commit comments

Comments
 (0)