Skip to content

Commit dfa52d0

Browse files
committed
Changed code blocks to use ```fsharp
1 parent a242ce1 commit dfa52d0

File tree

134 files changed

+3362
-3319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+3362
-3319
lines changed

_tools/Fixup.fsx

+48-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ System.IO.Directory.SetCurrentDirectory __SOURCE_DIRECTORY__
33
// ==============================================
44
// Script file to fixup files for publishing to GitBook
55
//
6-
// == Inputs and outputs ==
6+
// The idea is that I can copy the source .md files from the Jekyll-based static site
7+
// into the subdirectories here and then fix them up with this script
78
//
89
// The tool will process all code under the parent directory (../) by default
910

@@ -18,6 +19,8 @@ module Helpers =
1819
Regex.Replace(input,pattern,replacement)
1920

2021
(*
22+
// test the regexes
23+
2124
replaceRegex @"(?m)^\{\%\s+highlight.*?$" "```" "{% highlight fsharp %}\r\nabc"
2225
replaceRegex @"(?m)^\d\d\d\d-\d\d-\d\d-(.*?$)" "$1" "2012-09-01-myfile.md"
2326
@@ -32,11 +35,18 @@ module Helpers =
3235

3336
let ifNone v opt = defaultArg opt v
3437

38+
// ==========================
39+
// Rename and organize files
40+
//
41+
// This works only with newly copied files.
42+
// Any existing files must be deleted first.
43+
// ==========================
3544

3645
module FixupFiles =
3746

3847
let rec fixupFileNames (d:DirectoryInfo) =
3948

49+
// remove date "2014-08-12-XXX" prefix from files
4050
let renameIfNeeded (fi:FileInfo) =
4151
let oldName = fi.Name
4252
let newName = replaceRegex "(?m)^\d\d\d\d-\d\d-\d\d-(.*?$)" "$1" oldName
@@ -54,11 +64,20 @@ module FixupFiles =
5464
d.EnumerateDirectories()
5565
|> Seq.iter fixupFileNames
5666

67+
// ==========================
68+
// Fixup the text in the files
69+
//
70+
// * Replace Liquid code block markup {%highlight%} with GH markup (```)
71+
// * Replace absolute paths with relative ones, e.g. for /posts/ and /series/
72+
// * For video pages, replace relative ones with online absolute http links
73+
// * Fixup the smart quotes into ASCII friendly ones.
74+
// ==========================
75+
5776
module FixupText =
5877

5978
let replaceCodeBlockDelimiters text =
6079
text
61-
|> replaceRegex "(?m)^\{\%\s+highlight.*?$" "```"
80+
|> replaceRegex "(?m)^\{\%\s+highlight\s*(\S*).*\%\}.*$" "```$1"
6281
|> replaceRegex "(?m)^\{\%\s+endhighlight.*?$" "```"
6382

6483
let fixupLinkPaths text =
@@ -110,6 +129,14 @@ module FixupText =
110129
|> Seq.iter fixupDirectory
111130

112131

132+
// ==========================
133+
// Fixup the series pages
134+
//
135+
// In the Jekyll blog, the links for series pages are generated in the template
136+
// Instead, generate them explicitly here and append to the series page
137+
//
138+
// Note this should only be run once, otherwise another TOC will be appended!
139+
// ==========================
113140

114141
module Series =
115142

@@ -135,6 +162,8 @@ module Series =
135162
None
136163
)
137164
(*
165+
// test the regexes
166+
138167
let pattern = """title:\s*"([^"]+)"\s*"""
139168
let m = Regex.Match("""title:"abc" """,pattern) in m.Value
140169
let m = Regex.Match("""title:"abc" """,pattern) in m.Groups.[1].Value
@@ -165,6 +194,8 @@ module Series =
165194
}
166195

167196
(*
197+
// test the code
198+
168199
let fi = FileInfo("..")
169200
let lines =
170201
[
@@ -198,6 +229,7 @@ module Series =
198229
|> List.choose (fun (keyOpt,vals) -> keyOpt |> Option.map (fun key -> key,vals))
199230
|> Map.ofList
200231

232+
// test
201233
// Series.seriesIdToPostPages()
202234

203235
let seriesIdToSeriesIndexPages() =
@@ -208,6 +240,7 @@ module Series =
208240
|> Seq.toList
209241
|> List.choose (fun page -> page.SeriesIndexId |> Option.map (fun key -> key,page))
210242

243+
// test
211244
// Series.seriesIdToSeriesIndexPages()
212245

213246
type SeriesInfo = {
@@ -236,6 +269,16 @@ module Series =
236269
{SeriesPage=seriesPage; PostPages=postPages}
237270
)
238271
|> List.iter updateSeriesPageContent
272+
273+
// ==========================
274+
// Ensure all the images exist
275+
//
276+
// In the Jekyll blog, there are many image files. Only some are needed here.
277+
// So collect the image links from the posts, and check if they exist locally,
278+
// then emit a list of missing ones.
279+
//
280+
// Missing files are then copied over manually.
281+
// ==========================
239282

240283
module Images =
241284

@@ -258,15 +301,15 @@ module Images =
258301
imagePath
259302
|> File.Exists
260303

261-
let rec findImages (d:DirectoryInfo) =
304+
let rec collectMissingImages (d:DirectoryInfo) =
262305
seq {
263306
yield!
264307
d.EnumerateFiles("*.md")
265308
|> Seq.collect findImagesInFile
266309

267310
yield!
268311
d.EnumerateDirectories()
269-
|> Seq.collect findImages
312+
|> Seq.collect collectMissingImages
270313
}
271314
|> Seq.distinct
272315
|> Seq.toList
@@ -282,4 +325,4 @@ FixupText.fixupDirectory d
282325

283326
// Series.updateSeriesInfoPages()
284327

285-
Images.findImages d
328+
Images.collectMissingImages d

0 commit comments

Comments
 (0)