Initial Commit
This commit is contained in:
commit
711080f615
|
@ -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.
|
|
@ -0,0 +1,5 @@
|
|||
module test
|
||||
|
||||
go 1.13
|
||||
|
||||
require gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
@ -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=
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue