-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjekyll.build.ps1
131 lines (115 loc) · 3.83 KB
/
jekyll.build.ps1
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
#Requires -Module invokebuild
param(
[parameter()]$jekyllversion = '4',
[parameter()]$servecontainername = 'jekyll-serve',
[parameter()][string]$postname = '',
[parameter()][int]$cutoffMinutes = 5,
[switch]$wait
)
$rootdir = git rev-parse --show-toplevel
task proofread {
$learntospellyoudunce = @("kubernets", "kuberen", "oath", "serer", "challange")
$spellingmisstakes = gci "$rootdir/docs/_posts/*.md" | % {
gc $_ | Select-String -Pattern $learntospellyoudunce
}
if ($spellingmisstakes) {
$spellingmisstakes
throw 'learn to spell you dunce'
}
}
task new {
New-Item -ItemType Directory -ErrorAction SilentlyContinue -Path docs | Out-Null
push-location $rootdir/docs
#new
docker run --rm -it --volume="$($PWD):/srv/jekyll" --env JEKYLL_ENV=production jekyll/jekyll:4 jekyll new . --force
Pop-Location
}
task build {
if (-not (test-path .\docs)) {
throw "You cannot build what does not exist, run invokebuild new first!"
}
Push-Location $rootdir/docs
#build
docker run --rm -it --volume="$($PWD):/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" --env JEKYLL_ENV=production jekyll/jekyll:$jekyllversion /bin/sh -c "bundle install && jekyll build"
Pop-Location
}
task remove stop, {
icm { docker rm $servecontainername } -ea 0
}
task stop {
icm { docker stop $servecontainername } -ea 0
}
task serve stop, remove, {
if (-not (test-path .\docs)) {
throw "You cannot run what does not exist, run invokebuild new first!"
}
else {
Push-Location $rootdir/docs
#serve
docker run -d --name $servecontainername --volume="$($PWD):/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" --env JEKYLL_ENV=development -p 4000:4000 jekyll/jekyll:$jekyllversion jekyll serve --watch --drafts
Pop-Location
$tries = 15;
while ($wait -and $tries -gt 0) {
Start-Sleep 5
try {
$result = Invoke-WebRequest -Uri "http://localhost:4000"
if ($result.StatusCode -eq 200) {
Write-Host "Server is up"
$tries = 0;
break;
}
else {
Throw ("Server is not up")
}
}
catch {
Write-Host "Server is not up"
Start-Sleep 5;
$tries--;
}
}
}
}
task run serve
task surf {
Start-Process firefox "http://localhost:4000"
}
task newpost {
$df = get-date -Format 'yyyy-MM-dd'
if ($postname -eq '') {
$postname = read-host -Prompt 'What would you like to bestow upon your very limited social circle today?'
}
$postfile = New-Item "$rootdir/docs/_posts/$df-$($postname.Replace(' ','-').ToLower()).md"
@"
---
title: $postname
published: true
excerpt_separator: <!--more-->
---
Exerpt!
<!--more-->
Content here
"@ | out-file $postfile -Encoding utf8
code $postfile
}
task importImages {
if($IsLinux -eq $true) {
$screenshotdir = Get-Item ~/Pictures
$prefixToRemove = 'Screenshot from '
}
elseif($IsWindows -eq $true) {
$screenshotdir = Get-Item ~/OneDrive/Pictures/Screenshots
$prefixToRemove = 'Skärmbild '
}
if($screenshotdir -ne $null) {
Get-ChildItem $screenshotdir | Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-$cutoffMinutes) } | ForEach-Object {
$newname = $_.Name.Replace($prefixToRemove,'').Replace(' ','-').ToLower()
Write-Host "Copying $($_.FullName) to $rootdir/docs/assets/$newname"
Copy-Item $_.FullName "$rootdir/docs/assets/$newname"
}
}
else {
Write-Host "Couldn't import any screenshots, check the path [$screenshotdir]"
}
}
task . proofread, serve, surf