Skip to content

Commit 2623be0

Browse files
committed
feat: support !!python.
1 parent ec17416 commit 2623be0

File tree

3 files changed

+211
-8
lines changed

3 files changed

+211
-8
lines changed

manifest/fixtures/sample-mkdocs.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
site_name: drasyl
2+
site_description: drasyl Documentation
3+
site_author: drasyl
4+
site_url: https://docs.drasyl.org
5+
dev_addr: 0.0.0.0:8000
6+
7+
repo_name: 'drasyl-overlay/drasyl'
8+
repo_url: 'https://github.com/drasyl-overlay/drasyl'
9+
10+
edit_uri: https://git.informatik.uni-hamburg.de/sane-public/drasyl/-/edit/master/docs/content
11+
12+
docs_dir: 'content'
13+
14+
# https://squidfunk.github.io/mkdocs-material/
15+
theme:
16+
name: 'material'
17+
language: en
18+
include_sidebar: true
19+
favicon: assets/img/favicon.ico
20+
logo: assets/img/drasyl.png
21+
feature:
22+
tabs: false
23+
palette:
24+
primary: teal
25+
accent: teal
26+
i18n:
27+
prev: 'Previous'
28+
next: 'Next'
29+
icon:
30+
repo: fontawesome/brands/github
31+
32+
copyright: "Copyright © 2020 drasyl"
33+
34+
extra:
35+
social:
36+
- icon: fontawesome/brands/github
37+
link: https://github.com/drasyl-overlay/drasyl/
38+
name: GitHub repo of drasyl
39+
- icon: fontawesome/brands/gitlab
40+
link: https://git.informatik.uni-hamburg.de/sane-public/drasyl
41+
name: GitLab repo of drasyl
42+
- icon: fontawesome/brands/docker
43+
link: https://hub.docker.com/r/drasyl/drasyl
44+
name: Docker repo of drasyl
45+
46+
extra_css:
47+
- assets/style/content.css
48+
- assets/style/atom-one-light.css
49+
50+
extra_javascript:
51+
- assets/js/mermaid.min.js
52+
- assets/js/hljs/highlight.min.js # Download from https://highlightjs.org/download/
53+
- assets/js/extra.js
54+
55+
plugins:
56+
- search
57+
- git-revision-date-localized:
58+
type: date
59+
fallback_to_build_date: true
60+
61+
markdown_extensions:
62+
- admonition
63+
- toc:
64+
permalink: true
65+
- pymdownx.details
66+
- pymdownx.inlinehilite
67+
- pymdownx.highlight:
68+
use_pygments: false # hljs is used instead of pygment for TOML highlighting support
69+
- pymdownx.smartsymbols
70+
- pymdownx.superfences:
71+
# make exceptions to highlighting of code:
72+
custom_fences:
73+
- name: mermaid
74+
class: mermaid
75+
format: !!python/name:pymdownx.superfences.fence_div_format
76+
- pymdownx.tasklist
77+
78+
# Page tree
79+
nav:
80+
- 'Welcome': 'index.md'
81+
- 'Getting Started':
82+
- 'Quick Start': 'getting-started/quick-start.md'
83+
- 'Build': 'getting-started/build.md'
84+
- 'Snapshots': 'getting-started/snapshots.md'
85+
- 'CLI': 'getting-started/cli.md'
86+
- 'Super-Peers': 'getting-started/super-peers.md'
87+
- 'Configuration':
88+
- 'Overview': 'configuration/index.md'
89+
- 'Contributing':
90+
- 'Submitting Issues': 'contributing/submitting_issues.md'
91+
- 'Submiting PRs': 'contributing/submitting_pull_request.md'
92+
- 'Architecture':
93+
- 'Concepts': 'architecture/concepts.md'
94+
- 'Diagrams': 'architecture/diagrams.md'

manifest/manifest.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ const (
2121

2222
// Read Reads the manifest.
2323
func Read(manifestFilePath string) (map[string]interface{}, error) {
24-
bytes, err := ioutil.ReadFile(manifestFilePath)
24+
content, err := ioutil.ReadFile(manifestFilePath)
2525
if err != nil {
2626
return nil, fmt.Errorf("error when reading MkDocs Manifest: %w", err)
2727
}
2828

29-
bytes = replaceEnvVariables(bytes)
29+
content = replaceEnvVariables(content)
30+
content = regexp.MustCompile(`: (\!\!python.+)`).ReplaceAll(content, []byte(`: '$1'`))
3031

3132
manif := make(map[string]interface{})
3233

33-
if err = yaml.Unmarshal(bytes, manif); err != nil {
34+
if err = yaml.Unmarshal(content, manif); err != nil {
3435
return nil, fmt.Errorf("error when during unmarshal of the MkDocs Manifest: %w", err)
3536
}
3637

@@ -62,14 +63,15 @@ func rewriteEnvVariables(bytes []byte) []byte {
6263

6364
// Write Writes the manifest.
6465
func Write(manifestFilePath string, manif map[string]interface{}) error {
65-
out, err := yaml.Marshal(manif)
66+
content, err := yaml.Marshal(manif)
6667
if err != nil {
6768
return fmt.Errorf("error when marshal MkDocs Manifest: %w", err)
6869
}
6970

70-
out = rewriteEnvVariables(out)
71+
content = rewriteEnvVariables(content)
72+
content = regexp.MustCompile(`: '(\!\!python.+)'`).ReplaceAll(content, []byte(`: $1`))
7173

72-
return ioutil.WriteFile(manifestFilePath, out, os.ModePerm)
74+
return ioutil.WriteFile(manifestFilePath, content, os.ModePerm)
7375
}
7476

7577
// GetDocsDir returns the path to the directory pointed by "docs_dir" in the manifest file.

manifest/manifest_test.go

+109-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,119 @@ func TestRead(t *testing.T) {
1515
expected map[string]interface{}
1616
}{
1717
{
18-
desc: "",
18+
desc: "with !!python",
19+
filename: "sample-mkdocs.yml",
20+
expected: map[string]interface{}{
21+
"copyright": "Copyright © 2020 drasyl",
22+
"dev_addr": "0.0.0.0:8000",
23+
"docs_dir": "content",
24+
"edit_uri": "https://git.informatik.uni-hamburg.de/sane-public/drasyl/-/edit/master/docs/content",
25+
"extra": map[interface{}]interface{}{
26+
"social": []interface{}{
27+
map[interface{}]interface{}{
28+
"icon": "fontawesome/brands/github",
29+
"link": "https://github.com/drasyl-overlay/drasyl/",
30+
"name": "GitHub repo of drasyl",
31+
},
32+
map[interface{}]interface{}{
33+
"icon": "fontawesome/brands/gitlab",
34+
"link": "https://git.informatik.uni-hamburg.de/sane-public/drasyl",
35+
"name": "GitLab repo of drasyl",
36+
},
37+
map[interface{}]interface{}{
38+
"icon": "fontawesome/brands/docker",
39+
"link": "https://hub.docker.com/r/drasyl/drasyl",
40+
"name": "Docker repo of drasyl",
41+
},
42+
},
43+
},
44+
"extra_css": []interface{}{"assets/style/content.css", "assets/style/atom-one-light.css"},
45+
"extra_javascript": []interface{}{
46+
"assets/js/mermaid.min.js",
47+
"assets/js/hljs/highlight.min.js",
48+
"assets/js/extra.js",
49+
},
50+
"markdown_extensions": []interface{}{
51+
"admonition",
52+
map[interface{}]interface{}{"toc": map[interface{}]interface{}{"permalink": true}},
53+
"pymdownx.details",
54+
"pymdownx.inlinehilite",
55+
map[interface{}]interface{}{"pymdownx.highlight": map[interface{}]interface{}{"use_pygments": false}},
56+
"pymdownx.smartsymbols",
57+
map[interface{}]interface{}{"pymdownx.superfences": map[interface{}]interface{}{
58+
"custom_fences": []interface{}{map[interface{}]interface{}{
59+
"class": "mermaid",
60+
"format": "!!python/name:pymdownx.superfences.fence_div_format",
61+
"name": "mermaid",
62+
}},
63+
}},
64+
"pymdownx.tasklist",
65+
},
66+
"nav": []interface{}{
67+
map[interface{}]interface{}{"Welcome": "index.md"},
68+
map[interface{}]interface{}{
69+
"Getting Started": []interface{}{
70+
map[interface{}]interface{}{"Quick Start": "getting-started/quick-start.md"},
71+
map[interface{}]interface{}{"Build": "getting-started/build.md"},
72+
map[interface{}]interface{}{"Snapshots": "getting-started/snapshots.md"},
73+
map[interface{}]interface{}{"CLI": "getting-started/cli.md"},
74+
map[interface{}]interface{}{"Super-Peers": "getting-started/super-peers.md"},
75+
},
76+
},
77+
map[interface{}]interface{}{
78+
"Configuration": []interface{}{
79+
map[interface{}]interface{}{"Overview": "configuration/index.md"},
80+
},
81+
},
82+
map[interface{}]interface{}{"Contributing": []interface{}{
83+
map[interface{}]interface{}{"Submitting Issues": "contributing/submitting_issues.md"},
84+
map[interface{}]interface{}{"Submiting PRs": "contributing/submitting_pull_request.md"},
85+
}},
86+
map[interface{}]interface{}{
87+
"Architecture": []interface{}{
88+
map[interface{}]interface{}{"Concepts": "architecture/concepts.md"},
89+
map[interface{}]interface{}{"Diagrams": "architecture/diagrams.md"},
90+
},
91+
},
92+
},
93+
"plugins": []interface{}{
94+
"search",
95+
map[interface{}]interface{}{
96+
"git-revision-date-localized": map[interface{}]interface{}{"fallback_to_build_date": true, "type": "date"},
97+
},
98+
},
99+
"repo_name": "drasyl-overlay/drasyl",
100+
"repo_url": "https://github.com/drasyl-overlay/drasyl",
101+
"site_author": "drasyl",
102+
"site_description": "drasyl Documentation",
103+
"site_name": "drasyl",
104+
"site_url": "https://docs.drasyl.org",
105+
"theme": map[interface{}]interface{}{
106+
"favicon": "assets/img/favicon.ico",
107+
"feature": map[interface{}]interface{}{"tabs": false},
108+
"i18n": map[interface{}]interface{}{
109+
"next": "Next",
110+
"prev": "Previous",
111+
},
112+
"icon": map[interface{}]interface{}{"repo": "fontawesome/brands/github"},
113+
"include_sidebar": true,
114+
"language": "en",
115+
"logo": "assets/img/drasyl.png",
116+
"name": "material",
117+
"palette": map[interface{}]interface{}{
118+
"accent": "teal",
119+
"primary": "teal",
120+
},
121+
},
122+
},
123+
},
124+
{
125+
desc: "empty",
19126
filename: "empty-mkdocs.yml",
20127
expected: map[string]interface{}{},
21128
},
22129
{
23-
desc: "",
130+
desc: "traefik",
24131
filename: "traefik-mkdocs.yml",
25132
expected: map[string]interface{}{
26133
"site_name": "Traefik",

0 commit comments

Comments
 (0)