Skip to content

Commit 038c538

Browse files
committed
fix: /sources.json
correct path generation for 'loc' field in JSON output
1 parent 3d9c2f4 commit 038c538

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed
Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,61 @@
11
{{ $sources := slice }}
22

33
{{ range .Site.Sections }}
4-
{{ if .Params.source }}
5-
{{ $sectionLoc := printf "%s%s" .File.Dir .File.ContentBaseName | strings.TrimPrefix "/" }}
4+
{{ if .Params.source }}
5+
{{ $fullPath := strings.TrimSuffix "/" .File.Dir }}
6+
7+
{{ $transcripts := slice }}
8+
{{ $latestDate := "" }}
9+
10+
{{ range .Pages }}
11+
{{ $formattedDate := .Date.Format "2006-01-02" }}
12+
{{ $transcript := dict "title" .Title "media" .Params.media "episode" .Params.episode }}
13+
{{ if gt $formattedDate $latestDate }}
14+
{{ $latestDate = $formattedDate }}
15+
{{ end }}
16+
{{ $transcripts = $transcripts | append $transcript }}
17+
{{ end }}
18+
19+
{{ $sectionData := dict
20+
"title" .Title
21+
"source_file" .Params.source
22+
"transcripts" $transcripts
23+
"loc" $fullPath
24+
"transcription_coverage" .Params.transcription_coverage
25+
"cutoff_date" $latestDate
26+
}}
27+
28+
{{ $sources = $sources | append $sectionData }}
29+
{{ else }}
30+
{{ range .Pages }}
31+
{{ if and (eq .Kind "section") .Params.source }}
32+
{{ $fullPath := strings.TrimSuffix "/" .File.Dir }}
33+
634
{{ $transcripts := slice }}
735
{{ $latestDate := "" }}
836

937
{{ range .Pages }}
10-
{{ $formattedDate := .Params.date | dateFormat "2006-01-02" }}
11-
{{ $transcript := dict "title" .Title "media" .Params.media "episode" .Params.episode }}
12-
{{ if gt $formattedDate $latestDate }}
13-
{{ $latestDate = $formattedDate }}
14-
{{ end }}
15-
{{ $transcripts = $transcripts | append $transcript }}
38+
{{ $formattedDate := .Date.Format "2006-01-02" }}
39+
{{ $transcript := dict "title" .Title "media" .Params.media "episode" .Params.episode }}
40+
{{ if gt $formattedDate $latestDate }}
41+
{{ $latestDate = $formattedDate }}
42+
{{ end }}
43+
{{ $transcripts = $transcripts | append $transcript }}
1644
{{ end }}
17-
18-
{{ $sectionData := dict "title" .Title "source_file" .Params.source "transcripts" $transcripts "loc" $sectionLoc "transcription_coverage" .Params.transcription_coverage "cutoff_date" $latestDate }}
45+
46+
{{ $sectionData := dict
47+
"title" .Title
48+
"source_file" .Params.source
49+
"transcripts" $transcripts
50+
"loc" $fullPath
51+
"transcription_coverage" .Params.transcription_coverage
52+
"cutoff_date" $latestDate
53+
}}
54+
1955
{{ $sources = $sources | append $sectionData }}
20-
{{ else }}
21-
{{ range .Pages }}
22-
{{ if and (eq .BundleType "branch") .Params.source }}
23-
{{ $sourceLoc := printf "%s%s" .File.Dir .File.ContentBaseName | strings.TrimPrefix "/" }}
24-
{{ $transcripts := slice }}
25-
{{ $latestDate := "" }}
26-
27-
{{ range .Pages }}
28-
{{ $formattedDate := .Params.date | dateFormat "2006-01-02" }}
29-
{{ $transcript := dict "title" .Title "media" .Params.media "episode" .Params.episode }}
30-
{{ if gt $formattedDate $latestDate }}
31-
{{ $latestDate = $formattedDate }}
32-
{{ end }}
33-
{{ $transcripts = $transcripts | append $transcript }}
34-
{{ end }}
35-
36-
{{ $sourceData := dict "title" .Title "source_file" .Params.source "transcripts" $transcripts "loc" $sourceLoc "transcription_coverage" .Params.transcription_coverage "cutoff_date" $latestDate }}
37-
{{ $sources = $sources | append $sourceData }}
38-
{{ end }}
39-
{{ end }}
56+
{{ end }}
4057
{{ end }}
58+
{{ end }}
4159
{{ end }}
4260

43-
{{ jsonify $sources }}
61+
{{ $sources | jsonify }}

0 commit comments

Comments
 (0)