Skip to content

Commit 2952278

Browse files
committed
Script metadata work
1 parent d5fcec8 commit 2952278

File tree

26 files changed

+140
-37
lines changed

26 files changed

+140
-37
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defaults:
3535
layout: "docs"
3636
submodules:
3737
- "/assets/os2borgerpc-scripts/"
38+
- "/docs/scripts/core_scripts/"
3839

3940

4041
translations:

_includes/script_metadata.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% if page.source %}
22
<p><strong>Source:</strong>
3-
<a href="{{ page.source | relative_url }}" target="_blank">Download script</a>
4-
<button onclick="copyToClipboard('{{ page.source | relative_url }}')">Copy to Clipboard</button>
3+
<a href="{% script_url %}" target="_blank">Download script</a>
4+
<button onclick="copyToClipboard('{% script_url %}')">Copy to Clipboard</button>
55
</p>
66

77
<p><strong>Last Updated:</strong> {% last_modified_at %}</p>

_plugins/last_modified_at.rb

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@ def render(context)
1010
# Access frontmatter variables
1111
site_source = context.registers[:site].source
1212
page = context.registers[:page]
13+
page_url = page['url']
1314
source = page['source']
1415
submodules = page['submodules']
16+
submodule = ""
17+
18+
if submodules
19+
submodules.each do |sub|
20+
if page_url.include?(sub)
21+
submodule = sub
22+
end
23+
end
24+
end
25+
26+
# Concatenate submodule and source
27+
concatenated_path = submodule + source
1528

1629
# Script-repos are accesible as submodules
1730
# Locate the root of the submodule and the relative path to the script
18-
submodule_path, script_path = find_submodule_path(submodules, source)
19-
2031
# Use ruby-git to access the git log of the submodule
21-
if submodule_path
22-
submodule_source = File.join(site_source, submodule_path)
32+
if submodule
33+
submodule_source = File.join(site_source, submodule)
2334
submodule_repo = Git.open(submodule_source)
24-
log = submodule_repo.log.path(script_path).first
35+
log = submodule_repo.log.path(source).first
2536

2637
if log
2738
formatted_date = log.date.strftime("%-d. %B %Y")
@@ -34,19 +45,6 @@ def render(context)
3445
puts "Debug: Error - #{e.message}"
3546
"Unknown"
3647
end
37-
38-
private
39-
40-
def find_submodule_path(submodules, source)
41-
submodules.each do |submodule|
42-
if source.include?(submodule)
43-
script_path = source.split(submodule, 2).last
44-
return submodule, script_path
45-
end
46-
end
47-
[nil, nil]
48-
end
49-
5048
end
5149
end
5250

_plugins/read_script_content.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,23 @@ def render(context)
88
# Access frontmatter variables
99
site_source = context.registers[:site].source
1010
page = context.registers[:page]
11+
page_url = page['url']
1112
source = page['source']
13+
submodules = page['submodules']
14+
submodule = ""
1215

13-
file_path = File.join(site_source, source)
16+
if submodules
17+
submodules.each do |sub|
18+
if page_url.include?(sub)
19+
submodule = sub
20+
end
21+
end
22+
end
23+
24+
# Concatenate submodule and source
25+
concatenated_path = submodule + source
26+
27+
file_path = File.join(site_source, concatenated_path)
1428
if File.exist?(file_path)
1529
File.read(file_path)
1630
else

_plugins/script_url.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Jekyll
2+
class ScriptUrlTag < Liquid::Tag
3+
def initialize(tag_name, _text, tokens)
4+
super
5+
end
6+
7+
def render(context)
8+
# Access frontmatter variables
9+
site_source = context.registers[:site].source
10+
page = context.registers[:page]
11+
page_url = page['url']
12+
source = page['source']
13+
submodules = page['submodules']
14+
submodule = ""
15+
16+
if submodules
17+
submodules.each do |sub|
18+
if page_url.include?(sub)
19+
submodule = sub
20+
end
21+
end
22+
end
23+
24+
# Concatenate submodule and source
25+
concatenated_path = submodule + source
26+
27+
# Use the relative_url filter
28+
relative_url = Liquid::Template.parse("{{ '#{concatenated_path}' | relative_url }}").render(context)
29+
30+
relative_url
31+
end
32+
end
33+
end
34+
35+
Liquid::Template.register_tag('script_url', Jekyll::ScriptUrlTag)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Opgradering til 22.04"
3-
parent: Scripts
3+
parent: Script bibliotek
44
summary: |
55
Opgrader BorgerPC og Kiosk maskiner fra Ubuntu 20.04 til 22.04 via scripts.
66
---

docs/scripts/browser/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Browser
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Browser

docs/scripts/core_scripts

docs/scripts/desktop/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Desktop
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Desktop

docs/scripts/fejlfinding/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Fejlfinding
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Fejlfinding

docs/scripts/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
title: Scripts
2+
title: Script bibliotek
33
---
4-
Scripts
4+
Script bibliotek

docs/scripts/login/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Login
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Login

docs/scripts/lyd/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Lyd
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Lyd
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Kiosk
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
OS2BorgerPC Kiosk

docs/scripts/printer/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Printer
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Printer

docs/scripts/programmer/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Programmer
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Programmer

docs/scripts/sikkerhed/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Sikkerhed
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Sikkerhed

docs/scripts/skanner/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Skanner
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Skanner

docs/scripts/system/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: System
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
System

docs/scripts/udfases/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Udfases
3-
parent: Scripts
3+
parent: Script bibliotek
44
---
55
Udfases
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
title: Admin Site
3+
parent: Teknisk dokumentation
34
---
45
Admin Site
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Core scripts
3+
parent: Teknisk dokumentation
4+
---
5+
Core scripts er de

docs/teknisk dokumentation/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Teknisk dokumentation
3+
---
4+
Teknisk dokumentation
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Script metadata syntax
3+
parent: Teknisk dokumentation
4+
---
5+
6+
Each OS2borgerpc script must have a corresponding metadata-file.
7+
8+
The metadata-file is needed:
9+
- to load scripts into the admin-site
10+
- to generate the script library documentation.
11+
12+
The metadata is stored in the Markdown format with a [front matter](https://jekyllrb.com/docs/front-matter/) section at the beginning. The front matter section must contain a set of variables in a YAML format.
13+
14+
## Markdown document requirements
15+
The metadata document is a text file with an .md extension written in Markdown. Using the same name for the metadata-file and the script is a good idea, but not required. (F. ex. `reboot_now.md` ~ `reboot_now.sh`)
16+
17+
At the top of the metadata-file there must be a front matter section containg a set of variables in the YAML format. A front matter section starts and ends with three dashes:
18+
```
19+
---
20+
# Here goes the YAML
21+
---
22+
```
23+
24+
Below the front matter section you must provide a script description written using standard Markdown syntax.
25+
26+
Please include:
27+
- the use case for the script
28+
- any technical limitations or issues
29+
- dependencies on other scripts
30+
- partners who have contributed to writing or testing the script
31+
32+
## YAML section requirements
33+
Script metadata variables
34+
35+
| Variable | Description | Required |
36+
| ------------- | ------------------------------------------------------------ | --------- |
37+
| `title` | The title of the script. | Required |
38+
| `parent` | The script category. There can be only one. Supported values are: `Browser`, `Desktop`, `Fejlfinding`, `Kiosk`, `Login`, `Lyd`, `Opgradering`, `Printer`, `Programmer`, `Sikkerhed`, `Skanner`, `System`, `Udfases`| Required |
39+
| `source` | The relative path to the script-file (.sh/.py) from the metadata-file. | Required |
40+
| `parameters` | The list of parameters that the script expects to receive. <br> Each parameter is described by an array of 4 key/value pairs. <br> - `name`: The name of the parameter<br> - `type`: Supported values are `boolean`, `string`, `int`, `text_field`, `file`, `password`<br> - `default`: Default value of the parameter. `null` if none.<br> - `mandatory`: Required parameter? `true` or `false` <br> If the script expects leave the parameters-variable empty. | Required |
41+
| `compatibility` | Info about image and version compatibility. Supported values are: `20.04`, `22.04`, `24.04`, `BorgerPC` and `Kiosk`. More than one value can be supplied.| Optional |
42+
| `nav_exclude` | Should always be set to `true`. Needed by Just the docs for desired rendering. | Required |
43+
|`in_image`| Sometimes scripts get absorbed by the images, meaning that the script functionality is built into the image (borgerpc/kiosk) thereby making the script obsolete. When this happens please provide the image name and version tag here.| Optional |
44+
45+

0 commit comments

Comments
 (0)