Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
shihyuho committed Jun 19, 2021
1 parent 0025073 commit be1b01b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions toc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
{{- range $_, $season := index $courses $year }}
{{- range $_, $course := $season.Courses }}
- {{ $season.Season }} - [{{ $course.Course }}](/{{ $course.Year }}/{{ $course.Season }}/{{ $course.Course }}){{ if ne $course.Description "" }} - {{ $course.Description }}{{- end }}
- {{ $season.Season }} - [{{ $course.Course }}](/{{ $course.Year }}/{{ $course.Season }}/{{ $course.Course }}){{ if ne $course.Title "" }} - {{ $course.Title }}{{- end }}
{{- end }}
{{- end }}
{{- end }}`
Expand Down Expand Up @@ -101,13 +101,13 @@ func generateTOC(c *config) (err error) {
Season: filepath.Base(season),
Course: filepath.Base(path),
}
// 找看看課程目錄中的 README.md, 並試著擷取出第一個 header 作為課程說明
// 找看看課程目錄中的 README.md, 並試著擷取出第一個 header 作為課程標題
if md, err := ioutil.ReadFile(filepath.Join(path, "README.md")); err == nil {
re := regexp.MustCompile("#{1,6}\\s+(.+)")
match := re.FindStringSubmatch(string(md))
if len(match) > 0 {
if desc := match[1]; desc != c.Course { // 當說明跟課程名稱不一樣時才顯示
c.Description = strings.TrimSpace(desc)
if title := match[1]; title != c.Course { // 當課程標題跟課程名稱不一樣時才顯示
c.Title = strings.TrimSpace(title)
}
}
}
Expand Down Expand Up @@ -218,8 +218,8 @@ type Season struct {
}

type Course struct {
Year int
Season string
Course string
Description string
Year int
Season string
Course string
Title string
}
2 changes: 1 addition & 1 deletion toc/templates/readme.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
      └── ...
```

在你的課程目錄中, 如果有放一個 *README.md*, 會自動擷取該檔案中第一個 header (`#`, `##` ... `######`) 作為課程說明
在你的課程目錄中, 如果有放一個 *README.md*, 會自動擷取該檔案中第一個 header (`#`, `##` ... `######`) 作為課程標題

```sh
.
Expand Down
Binary file modified toc/toc-linux
Binary file not shown.
Binary file modified toc/toc-macos
Binary file not shown.
Binary file modified toc/toc-windows.exe
Binary file not shown.

0 comments on commit be1b01b

Please sign in to comment.