From 711080f61579ac12ffd81dc11b08258b57e732fe Mon Sep 17 00:00:00 2001 From: Donnie Date: Fri, 8 Jan 2021 16:08:29 -0600 Subject: [PATCH] Initial Commit --- README.md | 4 ++++ go.mod | 5 +++++ go.sum | 3 +++ main.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.yml | 5 +++++ 5 files changed, 84 insertions(+) create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 test.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..2af0dfe --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Offline Blog +This is an offline blog viewer. To make a blog post, please refer to [test.yml](/test.yml) + +To try out this on a real blog, [try mine](https://tildegit.org/kiiwiiwastaken/blog)! All you'll need is an executable of OB and the blog's git repo. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..908f776 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module test + +go 1.13 + +require gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7534661 --- /dev/null +++ b/go.sum @@ -0,0 +1,3 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..0ab926f --- /dev/null +++ b/main.go @@ -0,0 +1,67 @@ +package main + +import ( + // First-party packages + "flag" + "fmt" + "io/ioutil" + + // Third-party packages + "gopkg.in/yaml.v2" +) + +type OfflineTitle struct { + Title string `yaml:"title"` +} + +type OfflineDate struct { + Date string `yaml:"Date"` +} + +type OfflinePost struct { + Post struct { + Text string `yaml:"text"` + Links string `yaml:"links"` + } `yaml:"post"` +} + +func main() { + fmt.Println("Parsing YAML file") + + var fileName string + flag.StringVar(&fileName, "f", "", "YAML file to parse.") + flag.Parse() + + if fileName == "" { + fmt.Println("Please provide yaml file by using -f option") + return + } + + yamlFile, err := ioutil.ReadFile(fileName) + if err != nil { + fmt.Printf("Error reading YAML file: %s\n", err) + return + } + + var title OfflineTitle + err = yaml.Unmarshal(yamlFile, &title) + if err != nil { + fmt.Printf("Error parsing YAML file: %s\n", err) + } + + var date OfflineDate + err = yaml.Unmarshal(yamlFile, &date) + if err != nil { + fmt.Printf("Error parsing YAML file: %s\n", err) + } + + var post OfflinePost + err = yaml.Unmarshal(yamlFile, &post) + if err != nil { + fmt.Printf("Error parsing YAML file: %s\n", err) + } + + fmt.Println(title) + fmt.Println(date) + fmt.Println(post) +} \ No newline at end of file diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..e8a14b2 --- /dev/null +++ b/test.yml @@ -0,0 +1,5 @@ +title: "This is a test" +Date: "January 08, 2021" +post: + text: "Lorem ipsum dolor sit amet, magna feugait quaerendum ius at, mei meis altera splendide te, ei dicant accusam sit." + links: "\n[1] https://google.com/" \ No newline at end of file