Giter Site home page Giter Site logo

particle's Introduction

Build Status GoDoc

Particle

Particle is a go library that provides an Encoder/Decoder and Marshaler/Unmarshaler for frontmatter files.

A frontmatter file contains a block of metadata at the beginning of the file. This block is usually delimited by a --- or +++, as defined by Jekyll, however JSON may be included without a specific delimiter.

The Particle library can decode and encode frontmatter metadata blocks that are YAML, TOML or JSON. It is also a generic library so it's easy to define new custom block types to decode and encode as well.

See the GoDoc for more information.

Installation

go get github.com/njones/particle

Example of how to pull data from a frontmatter data string

package main

import (
  "fmt"

  "github.com/njones/particle"
)

var jsonFrontmatterFile = `
{
  "title":"front-matter example"
}

This is some example text
`

func main() {
  
  metadata := struct {
    Title string
  }{}

  body, err := particle.JSONEncoding.DecodeString(jsonFrontmatterFile, &metadata)
  if err != nil {
    // handle err
  }

  fmt.Println("Frontmatter metadata: %#v", metadata)
  fmt.Println("File body: %s", string(body))

}

Example of creating a frontmatter data string

package main

import (
  "fmt"

  "github.com/njones/particle"
)

func main() {
  
  metadata := struct {
    Title string
  }{
    Title: "front-matter example"
  }

  body := particle.JSONEncoding.EncodeToString([]byte("This is some example text\n"), &metadata)

  fmt.Println("File body: %s", body)

}

This package depends on the following external encoding/decoding libraries:

Note that the standard marshaling/unmarshaling function signatures can be used i.e func(interface{}) ([]byte error) and func([]byte, interface{}) error for the encoding and decoding of the frontmatter metadata.

License

Particle is available under the MIT License.

Copyright (c) 2016 Nika Jones [email protected] All Rights Reserved.

particle's People

Contributors

njones avatar

Watchers

James Cloos avatar Leo Palomares avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.