Skip to content

Commit

Permalink
Add footer template
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Hannaford committed May 16, 2017
1 parent ff667b8 commit 07082a2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
47 changes: 45 additions & 2 deletions build/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"os"
"time"

"github.com/cbroglie/mustache"
"gopkg.in/yaml.v2"
Expand All @@ -15,6 +16,7 @@ var (
templateDir = "build"
indexTemplate = fmt.Sprintf("%s/sig_index.mustache", templateDir)
listTemplate = fmt.Sprintf("%s/sig_list.mustache", templateDir)
footerTemplate = fmt.Sprintf("%s/footer.mustache", templateDir)
sigListOutput = "sig-list.md"
sigIndexOutput = "README.md"
)
Expand Down Expand Up @@ -53,6 +55,10 @@ type SigEntries struct {
Sigs []Sig
}

type Page struct {
LastGenerated string
}

func dirExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
Expand All @@ -64,6 +70,27 @@ func dirExists(path string) (bool, error) {
return true, err
}

func constructFooter() (data string, err error) {
template, err := mustache.ParseFile(footerTemplate)
if err != nil {
return
}

ctx := Page{LastGenerated: time.Now().Format("Mon Jan 2 2006 15:04:05")}

data, err = template.Render(ctx)
if err != nil {
return
}

err = ioutil.WriteFile(sigListOutput, []byte(data), 0644)
if err != nil {
return
}

return
}

func createReadmeFiles(ctx SigEntries) error {
template, err := mustache.ParseFile(indexTemplate)
if err != nil {
Expand All @@ -87,10 +114,18 @@ func createReadmeFiles(ctx SigEntries) error {
}
}

err = ioutil.WriteFile(fmt.Sprintf("%s/%s", sig.Dir, sigIndexOutput), []byte(data), 0644)
footer, err := constructFooter()
if err != nil {
return err
}

filePath := fmt.Sprintf("%s/%s", sig.Dir, sigIndexOutput)
err = ioutil.WriteFile(filePath, []byte(data+footer), 0644)
if err != nil {
return err
}

fmt.Printf("Generated %s\n", filePath)
}

return nil
Expand All @@ -107,11 +142,17 @@ func createListFile(ctx SigEntries) error {
return err
}

err = ioutil.WriteFile(sigListOutput, []byte(data), 0644)
footer, err := constructFooter()
if err != nil {
return err
}

err = ioutil.WriteFile(sigListOutput, []byte(data+footer), 0644)
if err != nil {
return err
}

fmt.Printf("Generated %s\n", sigListOutput)
return nil
}

Expand All @@ -136,4 +177,6 @@ func main() {
if err != nil {
log.Fatal(err)
}

fmt.Println("Finished generation!")
}
1 change: 1 addition & 0 deletions build/footer.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Last generated: {{LastGenerated}}
12 changes: 10 additions & 2 deletions build/sig_index.mustache
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<!---
This is an autogenerated file!
Please do not edit this file directly, but instead make changes to the
sigs.yaml file in the project root.
To understand how this file is generated, see build/README.md.
-->
# {{Name}} SIG

{{MissionStatement}}
## Meetings
{{#Meetings}}
- [{{Day}}s at {{UTC}} UTC]({{MeetingURL}}) ({{Frequency}})
* [{{Day}}s at {{UTC}} UTC]({{MeetingURL}}) ({{Frequency}})
{{/Meetings}}
Meeting notes and Agenda can be found [here]({{MeetingArchiveURL}}).

## Leads
{{#Leads}}
- [{{Name}}](https://github.com/{{GitHub}}){{#Company}}, {{Company}}{{/Company}}
* [{{Name}}](https://github.com/{{GitHub}}){{#Company}}, {{Company}}{{/Company}}
{{/Leads}}
## Contact
{{#Contact}}
Expand Down
10 changes: 9 additions & 1 deletion build/sig_list.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<!---
This is an autogenerated file!
Please do not edit this file directly, but instead make changes to the
sigs.yaml file in the project root.
To understand how this file is generated, see build/README.md.
-->
# SIGs and Working Groups

Most community activity is organized into Special Interest Groups (SIGs),
Expand All @@ -15,5 +23,5 @@ When the need arises, a [new SIG can be created](sig-creation-procedure.md)
| Name | Leads | Contact | Meetings |
|------|-------|---------|----------|
{{#Sigs}}
|[{{ Name }}]({{ Dir }}/README.md)|{{#Leads}}- [{{Name}}](https://github.com/{{GitHub}}){{#Company}}, {{Company}}{{/Company}}<br>{{/Leads}}|{{#Contact}}- [Slack](https://kubernetes.slack.com/messages/{{Slack}})<br>- [Mailing List]({{MailingList}}){{/Contact}}|{{#Meetings}}- [{{Day}}s at {{UTC}} UTC ({{Frequency}})]({{MeetingURL}})<br>{{/Meetings}}
|[{{ Name }}]({{ Dir }}/README.md)|{{#Leads}}* [{{Name}}](https://github.com/{{GitHub}}){{#Company}}, {{Company}}{{/Company}}<br>{{/Leads}}|{{#Contact}}* [Slack](https://kubernetes.slack.com/messages/{{Slack}})<br>* [Mailing List]({{MailingList}}){{/Contact}}|{{#Meetings}}* [{{Day}}s at {{UTC}} UTC ({{Frequency}})]({{MeetingURL}})<br>{{/Meetings}}
{{/Sigs}}

0 comments on commit 07082a2

Please sign in to comment.