diff options
-rw-r--r-- | main.go | 3 | ||||
-rw-r--r-- | templates/index.md.qtpl | 12 | ||||
-rw-r--r-- | templates/index.md.qtpl.go | 176 |
3 files changed, 106 insertions, 85 deletions
@@ -30,6 +30,7 @@ func fechIndex(url string) (io.ReadCloser, error) { func main() { url := flag.String("url", "", "Url to the APKINDEX.tar.gz") output := flag.String("output", "index.md", "Output path") + repositoryFormat := flag.String("repository-format", "https://git.sr.ht/~gabrielgio/apkbuilds/tree/%s/item/apks/%s", "Template to build repository link") flag.Parse() tarStream, err := fechIndex(*url) @@ -78,5 +79,5 @@ func main() { panic("Error opening output file: " + err.Error()) } - templates.WriteMarkdownTemplate(file, entries) + templates.WriteMarkdownTemplate(file, entries, *repositoryFormat) } diff --git a/templates/index.md.qtpl b/templates/index.md.qtpl index 80439c9..434d640 100644 --- a/templates/index.md.qtpl +++ b/templates/index.md.qtpl @@ -1,13 +1,19 @@ -{% import "git.sr.ht/~gabrielgio/apkdoc/parser" %} +{% import "fmt" %} {% import "strings" %} +{% import "git.sr.ht/~gabrielgio/apkdoc/parser" %} {% code func reduce(lines []string) string { return strings.Join(lines, " ") } + +func formatLink(e *parser.Entry, format string) string { + c := strings.Replace(*e.Commit, "-dirty", "", -1) + return fmt.Sprintf(format, c, *e.Origin) +} %} -{% func MarkdownTemplate(entries []*parser.Entry) %} +{% func MarkdownTemplate(entries []*parser.Entry, format string) %} # Apks Alpine 3.18 {% for _, e := range entries %} ## {%s e.Name %} @@ -23,7 +29,7 @@ func reduce(lines []string) string { - **License**: {%s e.License%}{% if e.Origin != nil %} - **Origin**: {%s *e.Origin%}{% endif %}{% if e.BuildTime != nil %} - **Build time**: {%s e.BuildTime.String() %}{% endif %}{% if e.Commit != nil %} -- **Commit**: {%s *e.Commit %}{% endif %}{% if e.ProviderPriority != nil %} +- **Commit**: [{%s *e.Commit %}]({%s formatLink(e, format) %}){% endif %}{% if e.ProviderPriority != nil %} - **Provider Priority**: {%d *e.ProviderPriority %}{% endif %}{% if len(e.Dependencies) > 0 %} - **Dependencies:**: {%s reduce(e.Dependencies) %}{% endif %}{% if len(e.Provides) > 0 %} - **Provides:**: {%s reduce(e.Provides) %}{% endif %}{% if len(e.InstallIf) > 0 %} diff --git a/templates/index.md.qtpl.go b/templates/index.md.qtpl.go index 9229465..c87d947 100644 --- a/templates/index.md.qtpl.go +++ b/templates/index.md.qtpl.go @@ -5,193 +5,207 @@ package templates //line index.md.qtpl:1 -import "git.sr.ht/~gabrielgio/apkdoc/parser" +import "fmt" //line index.md.qtpl:2 import "strings" -//line index.md.qtpl:4 +//line index.md.qtpl:3 +import "git.sr.ht/~gabrielgio/apkdoc/parser" + +//line index.md.qtpl:5 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line index.md.qtpl:4 +//line index.md.qtpl:5 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line index.md.qtpl:5 +//line index.md.qtpl:6 func reduce(lines []string) string { return strings.Join(lines, " ") } -//line index.md.qtpl:10 -func StreamMarkdownTemplate(qw422016 *qt422016.Writer, entries []*parser.Entry) { -//line index.md.qtpl:10 +func formatLink(e *parser.Entry, format string) string { + c := strings.Replace(*e.Commit, "-dirty", "", -1) + return fmt.Sprintf(format, c, *e.Origin) +} + +//line index.md.qtpl:16 +func StreamMarkdownTemplate(qw422016 *qt422016.Writer, entries []*parser.Entry, format string) { +//line index.md.qtpl:16 qw422016.N().S(` # Apks Alpine 3.18 `) -//line index.md.qtpl:12 +//line index.md.qtpl:18 for _, e := range entries { -//line index.md.qtpl:12 +//line index.md.qtpl:18 qw422016.N().S(` ## `) -//line index.md.qtpl:13 +//line index.md.qtpl:19 qw422016.E().S(e.Name) -//line index.md.qtpl:13 +//line index.md.qtpl:19 qw422016.N().S(` - **Version**: `) -//line index.md.qtpl:15 +//line index.md.qtpl:21 qw422016.E().S(e.Version) -//line index.md.qtpl:15 +//line index.md.qtpl:21 qw422016.N().S(` - **Description**: `) -//line index.md.qtpl:16 +//line index.md.qtpl:22 qw422016.E().S(e.Description) -//line index.md.qtpl:16 +//line index.md.qtpl:22 if e.Maintainer != nil { -//line index.md.qtpl:16 +//line index.md.qtpl:22 qw422016.N().S(` - **Maintainer**: `) -//line index.md.qtpl:17 +//line index.md.qtpl:23 qw422016.E().S(*e.Maintainer) -//line index.md.qtpl:17 +//line index.md.qtpl:23 } -//line index.md.qtpl:17 +//line index.md.qtpl:23 qw422016.N().S(` - **Checksum**:`) -//line index.md.qtpl:18 +//line index.md.qtpl:24 qw422016.E().S(e.Checksum) -//line index.md.qtpl:18 +//line index.md.qtpl:24 if e.Architecture != nil { -//line index.md.qtpl:18 +//line index.md.qtpl:24 qw422016.N().S(` - **Architecture**: `) -//line index.md.qtpl:19 +//line index.md.qtpl:25 qw422016.E().S(*e.Architecture) -//line index.md.qtpl:19 +//line index.md.qtpl:25 } -//line index.md.qtpl:19 +//line index.md.qtpl:25 qw422016.N().S(` - **Size**: `) -//line index.md.qtpl:20 +//line index.md.qtpl:26 qw422016.N().D(e.PackageSize) -//line index.md.qtpl:20 +//line index.md.qtpl:26 qw422016.N().S(`B - **Installed size**: `) -//line index.md.qtpl:21 +//line index.md.qtpl:27 qw422016.N().D(e.InstalledSize) -//line index.md.qtpl:21 +//line index.md.qtpl:27 qw422016.N().S(` - **Url**: `) -//line index.md.qtpl:22 +//line index.md.qtpl:28 qw422016.E().S(e.Url) -//line index.md.qtpl:22 +//line index.md.qtpl:28 qw422016.N().S(` - **License**: `) -//line index.md.qtpl:23 +//line index.md.qtpl:29 qw422016.E().S(e.License) -//line index.md.qtpl:23 +//line index.md.qtpl:29 if e.Origin != nil { -//line index.md.qtpl:23 +//line index.md.qtpl:29 qw422016.N().S(` - **Origin**: `) -//line index.md.qtpl:24 +//line index.md.qtpl:30 qw422016.E().S(*e.Origin) -//line index.md.qtpl:24 +//line index.md.qtpl:30 } -//line index.md.qtpl:24 +//line index.md.qtpl:30 if e.BuildTime != nil { -//line index.md.qtpl:24 +//line index.md.qtpl:30 qw422016.N().S(` - **Build time**: `) -//line index.md.qtpl:25 +//line index.md.qtpl:31 qw422016.E().S(e.BuildTime.String()) -//line index.md.qtpl:25 +//line index.md.qtpl:31 } -//line index.md.qtpl:25 +//line index.md.qtpl:31 if e.Commit != nil { -//line index.md.qtpl:25 +//line index.md.qtpl:31 qw422016.N().S(` -- **Commit**: `) -//line index.md.qtpl:26 +- **Commit**: [`) +//line index.md.qtpl:32 qw422016.E().S(*e.Commit) -//line index.md.qtpl:26 +//line index.md.qtpl:32 + qw422016.N().S(`](`) +//line index.md.qtpl:32 + qw422016.E().S(formatLink(e, format)) +//line index.md.qtpl:32 + qw422016.N().S(`)`) +//line index.md.qtpl:32 } -//line index.md.qtpl:26 +//line index.md.qtpl:32 if e.ProviderPriority != nil { -//line index.md.qtpl:26 +//line index.md.qtpl:32 qw422016.N().S(` - **Provider Priority**: `) -//line index.md.qtpl:27 +//line index.md.qtpl:33 qw422016.N().D(*e.ProviderPriority) -//line index.md.qtpl:27 +//line index.md.qtpl:33 } -//line index.md.qtpl:27 +//line index.md.qtpl:33 if len(e.Dependencies) > 0 { -//line index.md.qtpl:27 +//line index.md.qtpl:33 qw422016.N().S(` - **Dependencies:**: `) -//line index.md.qtpl:28 +//line index.md.qtpl:34 qw422016.E().S(reduce(e.Dependencies)) -//line index.md.qtpl:28 +//line index.md.qtpl:34 } -//line index.md.qtpl:28 +//line index.md.qtpl:34 if len(e.Provides) > 0 { -//line index.md.qtpl:28 +//line index.md.qtpl:34 qw422016.N().S(` - **Provides:**: `) -//line index.md.qtpl:29 +//line index.md.qtpl:35 qw422016.E().S(reduce(e.Provides)) -//line index.md.qtpl:29 +//line index.md.qtpl:35 } -//line index.md.qtpl:29 +//line index.md.qtpl:35 if len(e.InstallIf) > 0 { -//line index.md.qtpl:29 +//line index.md.qtpl:35 qw422016.N().S(` - **Install if:**: `) -//line index.md.qtpl:30 +//line index.md.qtpl:36 qw422016.E().S(reduce(e.InstallIf)) -//line index.md.qtpl:30 +//line index.md.qtpl:36 } -//line index.md.qtpl:30 +//line index.md.qtpl:36 qw422016.N().S(` `) -//line index.md.qtpl:31 +//line index.md.qtpl:37 } -//line index.md.qtpl:31 +//line index.md.qtpl:37 qw422016.N().S(` `) -//line index.md.qtpl:33 +//line index.md.qtpl:39 } -//line index.md.qtpl:33 -func WriteMarkdownTemplate(qq422016 qtio422016.Writer, entries []*parser.Entry) { -//line index.md.qtpl:33 +//line index.md.qtpl:39 +func WriteMarkdownTemplate(qq422016 qtio422016.Writer, entries []*parser.Entry, format string) { +//line index.md.qtpl:39 qw422016 := qt422016.AcquireWriter(qq422016) -//line index.md.qtpl:33 - StreamMarkdownTemplate(qw422016, entries) -//line index.md.qtpl:33 +//line index.md.qtpl:39 + StreamMarkdownTemplate(qw422016, entries, format) +//line index.md.qtpl:39 qt422016.ReleaseWriter(qw422016) -//line index.md.qtpl:33 +//line index.md.qtpl:39 } -//line index.md.qtpl:33 -func MarkdownTemplate(entries []*parser.Entry) string { -//line index.md.qtpl:33 +//line index.md.qtpl:39 +func MarkdownTemplate(entries []*parser.Entry, format string) string { +//line index.md.qtpl:39 qb422016 := qt422016.AcquireByteBuffer() -//line index.md.qtpl:33 - WriteMarkdownTemplate(qb422016, entries) -//line index.md.qtpl:33 +//line index.md.qtpl:39 + WriteMarkdownTemplate(qb422016, entries, format) +//line index.md.qtpl:39 qs422016 := string(qb422016.B) -//line index.md.qtpl:33 +//line index.md.qtpl:39 qt422016.ReleaseByteBuffer(qb422016) -//line index.md.qtpl:33 +//line index.md.qtpl:39 return qs422016 -//line index.md.qtpl:33 +//line index.md.qtpl:39 } |