forked from xarantolus/fdroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generate apps listing in README
- Loading branch information
1 parent
595e1a1
commit 58a335c
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package md | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"html/template" | ||
"metascoop/apps" | ||
"os" | ||
) | ||
|
||
const ( | ||
tableStart = "<!-- This table is auto-generated. Do not edit -->" | ||
|
||
tableEnd = "<!-- end apps table -->" | ||
|
||
tableTmpl = ` | ||
| Icon | Name | Description | Version | | ||
| --- | --- | --- | --- |{{range .Apps}} | ||
| <a href="{{.sourceCode}}"><img src="fdroid/repo/icons/{{.icon}}" alt="{{.name}} icon" width="36px" height="36px"></a> | [**{{.name}}**]({{.sourceCode}}) | {{.summary}} | {{.suggestedVersionName}} ({{.suggestedVersionCode}}) |{{end}} | ||
` + tableEnd | ||
) | ||
|
||
var tmpl = template.Must(template.New("").Parse(tableTmpl)) | ||
|
||
func RegenerateReadme(readMePath string, index *apps.RepoIndex) (err error) { | ||
content, err := os.ReadFile(readMePath) | ||
if err != nil { | ||
return | ||
} | ||
|
||
var tableStartIndex = bytes.Index(content, []byte(tableStart)) | ||
if tableStartIndex < 0 { | ||
return fmt.Errorf("cannot find table start in %q", readMePath) | ||
} | ||
|
||
var tableEndIndex = bytes.Index(content, []byte(tableEnd)) | ||
if tableEndIndex < 0 { | ||
return fmt.Errorf("cannot find table end in %q", readMePath) | ||
} | ||
|
||
var table bytes.Buffer | ||
|
||
table.WriteString(tableStart) | ||
|
||
err = tmpl.Execute(&table, index) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
newContent := []byte{} | ||
|
||
newContent = append(newContent, content[:tableStartIndex]...) | ||
newContent = append(newContent, table.Bytes()...) | ||
newContent = append(newContent, content[tableEndIndex:]...) | ||
|
||
return os.WriteFile(readMePath, newContent, os.ModePerm) | ||
} |