|
1 | 1 | {{- $params := site.Params.hb.content_panel.repo }}
|
2 | 2 | {{- $page := . }}
|
3 | 3 | {{- with $params }}
|
4 |
| - {{- $github := dict |
5 |
| - "baseURL" "https://github.com/%s" |
6 |
| - "editURL" "%s/edit/%s/%s" |
7 |
| - "viewURL" "%s/blob/%s/%s" |
8 |
| - "commitURL" "%s/commit/%s" |
9 |
| - }} |
10 |
| - {{- $gitlab := dict |
11 |
| - "baseURL" "https://gitlab.com/%s" |
12 |
| - "editURL" "%s/-/edit/%s/%s" |
13 |
| - "viewURL" "%s/-/blob/%s/%s" |
14 |
| - "commitURL" "%s/-/commit/%s" |
15 |
| - }} |
16 |
| - {{- $services := dict |
17 |
| - "github" $github |
18 |
| - "gitlab" $gitlab |
19 |
| - }} |
| 4 | + {{- $services := partialCached "hb/modules/content-panel/functions/repo-services" . }} |
20 | 5 | {{- $root := partialCached "hb/modules/content-panel/functions/working-directory" . }}
|
21 |
| - {{- with index $services .service }} |
22 |
| - {{- $branch := default "main" $params.branch }} |
23 |
| - {{- $subpath := "" }} |
24 |
| - {{- with $params.subpath }} |
25 |
| - {{- $subpath = printf "/%s" . }} |
26 |
| - {{- end }} |
27 |
| - {{- $baseURL := printf .baseURL $params.repo }} |
28 |
| - {{- $filepath := "" }} |
29 |
| - {{- with $page.File }} |
30 |
| - {{- $filepath = printf "%s%s" $subpath (strings.TrimPrefix $root .Filename) -}} |
31 |
| - {{- end }} |
32 |
| - {{/* replace the path separator to / when running Hugo server on Windows. */}} |
33 |
| - {{- $filepath = replace $filepath "\\" "/" }} |
34 |
| - {{- $editURL := printf .editURL $baseURL $branch $filepath }} |
35 |
| - {{- $viewURL := printf .viewURL $baseURL $branch $filepath }} |
36 |
| - {{- $commitURL := .commitURL }} |
37 |
| - {{- $editIcon := dict "vendor" "bs" "name" "pencil-square" }} |
38 |
| - {{- $pencilIcon := dict "vendor" "bs" "name" "pencil" "className" "me-2" }} |
39 |
| - {{- $viewIcon := dict "vendor" "bs" "name" "eye" "className" "me-2" }} |
40 |
| - {{- $commitIcon := dict "vendor" "bs" "name" "git" "className" "me-2" }} |
41 |
| - <div |
42 |
| - class="hb-content-panel-item hb-content-panel-repo dropup-center dropup"> |
43 |
| - <button |
44 |
| - class="btn btn-link text-body" |
45 |
| - type="button" |
46 |
| - title="{{ i18n `edit` }}" |
47 |
| - data-bs-toggle="dropdown" |
48 |
| - aria-expanded="false"> |
49 |
| - {{- partialCached "icons/icon" $editIcon $editIcon }} |
50 |
| - </button> |
51 |
| - <ul class="dropdown-menu"> |
52 |
| - <li> |
53 |
| - <a |
54 |
| - class="dropdown-item" |
55 |
| - href="{{ $editURL }}" |
56 |
| - target="_blank" |
57 |
| - rel="noreferrer noopener"> |
58 |
| - {{- partialCached "icons/icon" $pencilIcon $pencilIcon -}} |
59 |
| - {{- i18n "edit_the_page" -}} |
60 |
| - </a> |
61 |
| - </li> |
| 6 | + {{- $srvBaseURL := "" }} |
| 7 | + {{- $srvCommitPath := "commit" }} |
| 8 | + {{- $srvEditPath := "edit" }} |
| 9 | + {{- $srvSourcePath := "blob" }} |
| 10 | + {{- with index $services (default "github" .service) }} |
| 11 | + {{- with .baseURL }}{{ $srvBaseURL = . }}{{ end }} |
| 12 | + {{- with .commitPath }}{{ $srvCommitPath = . }}{{ end }} |
| 13 | + {{- with .editPath }}{{ $srvEditPath = . }}{{ end }} |
| 14 | + {{- with .sourcePath }}{{ $srvSourcePath = . }}{{ end }} |
| 15 | + {{- end }} |
| 16 | + {{- with $params.service_baseurl }} |
| 17 | + {{- $srvBaseURL = strings.TrimSuffix "/" . }} |
| 18 | + {{- end }} |
| 19 | + {{- $branch := default "main" $params.branch }} |
| 20 | + {{- $baseURL := printf "%s/%s" $srvBaseURL $params.repo }} |
| 21 | + {{- $subpath := "" }} |
| 22 | + {{- with $params.subpath }} |
| 23 | + {{- $subpath = printf "/%s" . }} |
| 24 | + {{- end }} |
| 25 | + {{- $filepath := "" }} |
| 26 | + {{- with $page.File }} |
| 27 | + {{- $filepath = printf "%s%s" $subpath (strings.TrimPrefix $root .Filename) -}} |
| 28 | + {{- end }} |
| 29 | + {{/* replace the path separator to / when running Hugo server on Windows. */}} |
| 30 | + {{- $filepath = replace $filepath "\\" "/" | strings.TrimPrefix "/" }} |
| 31 | + {{- $editURL := printf "%s/%s/%s/%s" $baseURL $srvEditPath $branch $filepath }} |
| 32 | + {{- $sourceURL := printf "%s/%s/%s/%s" $baseURL $srvSourcePath $branch $filepath }} |
| 33 | + {{- $editIcon := dict "vendor" "bs" "name" "pencil-square" }} |
| 34 | + {{- $pencilIcon := dict "vendor" "bs" "name" "pencil" "className" "me-2" }} |
| 35 | + {{- $viewIcon := dict "vendor" "bs" "name" "eye" "className" "me-2" }} |
| 36 | + {{- $commitIcon := dict "vendor" "bs" "name" "git" "className" "me-2" }} |
| 37 | + <div |
| 38 | + class="hb-content-panel-item hb-content-panel-repo dropup-center dropup"> |
| 39 | + <button |
| 40 | + class="btn btn-link text-body" |
| 41 | + type="button" |
| 42 | + title="{{ i18n `edit` }}" |
| 43 | + data-bs-toggle="dropdown" |
| 44 | + aria-expanded="false"> |
| 45 | + {{- partialCached "icons/icon" $editIcon $editIcon }} |
| 46 | + </button> |
| 47 | + <ul class="dropdown-menu"> |
| 48 | + <li> |
| 49 | + <a |
| 50 | + class="dropdown-item" |
| 51 | + href="{{ $editURL }}" |
| 52 | + target="_blank" |
| 53 | + rel="noreferrer noopener"> |
| 54 | + {{- partialCached "icons/icon" $pencilIcon $pencilIcon -}} |
| 55 | + {{- i18n "edit_the_page" -}} |
| 56 | + </a> |
| 57 | + </li> |
| 58 | + <li> |
| 59 | + <a |
| 60 | + class="dropdown-item" |
| 61 | + href="{{ $sourceURL }}" |
| 62 | + target="_blank" |
| 63 | + rel="noreferrer noopener"> |
| 64 | + {{- partialCached "icons/icon" $viewIcon $viewIcon -}} |
| 65 | + {{- i18n "view_the_page_source" -}} |
| 66 | + </a> |
| 67 | + </li> |
| 68 | + {{- with $page.GitInfo }} |
62 | 69 | <li>
|
63 | 70 | <a
|
64 | 71 | class="dropdown-item"
|
65 |
| - href="{{ $viewURL }}" |
| 72 | + href="{{ printf `%s/%s/%s` $baseURL $srvCommitPath .Hash }}" |
66 | 73 | target="_blank"
|
67 | 74 | rel="noreferrer noopener">
|
68 |
| - {{- partialCached "icons/icon" $viewIcon $viewIcon -}} |
69 |
| - {{- i18n "view_the_page_source" -}} |
| 75 | + {{- partialCached "icons/icon" $commitIcon $commitIcon -}} |
| 76 | + {{- .AbbreviatedHash -}} |
70 | 77 | </a>
|
71 | 78 | </li>
|
72 |
| - {{- with $page.GitInfo }} |
73 |
| - <li> |
74 |
| - <a |
75 |
| - class="dropdown-item" |
76 |
| - href="{{ printf $commitURL $baseURL .Hash }}" |
77 |
| - target="_blank" |
78 |
| - rel="noreferrer noopener"> |
79 |
| - {{- partialCached "icons/icon" $commitIcon $commitIcon -}} |
80 |
| - {{- .AbbreviatedHash -}} |
81 |
| - </a> |
82 |
| - </li> |
83 |
| - {{- end }} |
84 |
| - </ul> |
85 |
| - </div> |
86 |
| - {{- else }} |
87 |
| - {{- warnf "[content-panel] unsupported service: %s" .service }} |
88 |
| - {{- end }} |
| 79 | + {{- end }} |
| 80 | + </ul> |
| 81 | + </div> |
89 | 82 | {{- end }}
|
0 commit comments