Initial Commit

This commit is contained in:
Donnie 2021-01-08 16:08:29 -06:00
commit 711080f615
5 changed files with 84 additions and 0 deletions

4
README.md Normal file
View File

@ -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.

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module test
go 1.13
require gopkg.in/yaml.v2 v2.4.0 // indirect

3
go.sum Normal file
View File

@ -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=

67
main.go Normal file
View File

@ -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)
}

5
test.yml Normal file
View File

@ -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/"