googledrive2hugo

package module
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2018 License: MIT Imports: 28 Imported by: 0

README

googledrive2hugo

Converts google docs to Hugo HTML content files WIP

HEY, THIS IS ALPHA. Names (this repo, package, functions) will change.

The Goal is to edit Google Docs content in Google Drive and then use Hugo (and friends) to publish it.

We do this by:

  • Reading a folder of Google Docs off a Google Drive
  • Convert to HTML with Hugo front matter
  • Place output in a Hugo site directory

From there you publish in a few ways

  • Run Hugo and serve directly or publish output
  • Commit the generated content template pages, trigger Travis-CI, whatever

Challenges

  • Permissions (Google OAuth) is a bit painful to set up
  • Google Docs HTML output is crazy
  • Google Docs only supports one type of paragraph style, so code blocks and blockquotes have to be inferred
  • Unclear on what to do with images for now
  • Indents are sometimes done with 8 nbsp; and sometimes with margin-left:36pt

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportHTML

func ExportHTML(srv *drive.Service, f *drive.File) ([]byte, error)

ExportHTML downloads a Google Doc as HTML

Download as Zip and unzip

func FileInfoToMeta

func FileInfoToMeta(fileInfo *drive.File) map[string]interface{}

output map is the one used by Hugo

func GdocAttr

func GdocAttr(root *html.Node) error

GDocAttr remove all unnessecary attributes from a GDoc HTML tree in particular removes all attributes except

  • id
  • href
  • colspan,rowspan if not "1"

TODO: probably can optimize this by skipping recusion on text-nodes

func GdocBlockquote

func GdocBlockquote(root *html.Node) error

GdocBlockquote converts a sequence of <p style="margin-left:36pt"> to a blockquote

func GdocBlockquotePre

func GdocBlockquotePre(root *html.Node) error

func GdocCodeBlock

func GdocCodeBlock(root *html.Node) error

func GdocImg

func GdocImg(root *html.Node) error

converts <p><span><img/></span><sup><a></a></sup></p> into a nice <p><img> comment is in form of

<sup><a href="#cmnt1" id="cmnt_ref1">[a]</a></sup>

func GdocSpan

func GdocSpan(root *html.Node) error

converts span wrappers to a series of <b><i><code> elements

func GdocTable

func GdocTable(root *html.Node) error

ConvertGdocTables cleans up tables found in gdocs

Removes redundant <p> inside each <td>
If first row had bold <td> elements, convert the row into
  a <thead> with <th> elements

func HugoContentWrite

func HugoContentWrite(content []byte, metamap map[string]interface{}) ([]byte, error)

HugoContent takes front-matter data, content and writes it to output stream

func HugoFrontMatter

func HugoFrontMatter(root *html.Node) (map[string]interface{}, error)

func IsDir

func IsDir(f *drive.File) bool

func IsGoogleDoc

func IsGoogleDoc(f *drive.File) bool

func MetaMerge

func MetaMerge(a, b map[string]interface{}) map[string]interface{}

merge B into A

func Setup

func Setup() (*drive.Service, error)

setup is a temp function to read secrets and make a drive service

func URLize

func URLize(path string) string

URLize takes a path and converts into something nice for a URL

func UnicodeSanitize

func UnicodeSanitize(s string) string

UnicodeSanitize sanitizes string to be used in Hugo URL's, allowing only a predefined set of special Unicode characters. If RemovePathAccents configuration flag is enabled, Uniccode accents are also removed. TODO: From Hugo github.com/gohugoio/hugo/helpers/path.go

func Walk

func Walk(srv *drive.Service, root string, walkfn WalkFunc) error

Types

type AddClassAttr

type AddClassAttr struct {
	// contains filtered or unexported fields
}

func (*AddClassAttr) Init added in v0.0.4

func (a *AddClassAttr) Init(pattern string, newcss string) (err error)

func (*AddClassAttr) Run

func (a *AddClassAttr) Run(n *html.Node, log ilog.Logger) (err error)

type Converter

type Converter struct {
	Logger  ilog.Logger
	Filters []Runner
}

func (*Converter) FromNode

func (c *Converter) FromNode(root *html.Node) ([]byte, map[string]interface{}, error)

if you already have a google doc node

func (*Converter) ToHTML

func (c *Converter) ToHTML(src []byte, fileMeta map[string]interface{}) ([]byte, error)

type LinkInsecure

type LinkInsecure struct {
	Whitelist []string
	// contains filtered or unexported fields
}

func (*LinkInsecure) Init added in v0.0.4

func (n *LinkInsecure) Init(list []string) (err error)

func (*LinkInsecure) Run

func (n *LinkInsecure) Run(root *html.Node, log ilog.Logger) (err error)

type LinkRelative

type LinkRelative struct {
	// contains filtered or unexported fields
}

func (*LinkRelative) Init added in v0.0.4

func (n *LinkRelative) Init(host string) (err error)

func (*LinkRelative) Run

func (n *LinkRelative) Run(root *html.Node, log ilog.Logger) (err error)

type NarrowTag

type NarrowTag struct {
	// contains filtered or unexported fields
}

func (*NarrowTag) Init added in v0.0.4

func (n *NarrowTag) Init() (err error)

func (*NarrowTag) Run

func (n *NarrowTag) Run(root *html.Node, log ilog.Logger) (err error)

type Punc

type Punc struct {
	// contains filtered or unexported fields
}

func (*Punc) Init added in v0.0.4

func (n *Punc) Init() (err error)

func (*Punc) Run

func (n *Punc) Run(root *html.Node, log ilog.Logger) error

type RemoveEmptyTag

type RemoveEmptyTag struct {
	// contains filtered or unexported fields
}

remove some empty tags <p></p> is used a typically unintended line spaces <a></a> is in docs for unknown reasons

func (*RemoveEmptyTag) Init added in v0.0.4

func (n *RemoveEmptyTag) Init() (err error)

func (*RemoveEmptyTag) Run

func (n *RemoveEmptyTag) Run(root *html.Node, logger ilog.Logger) error

type Runner

type Runner interface {
	Run(root *html.Node, log ilog.Logger) error
}

func Parse added in v0.0.4

func Parse(text string) ([]Runner, error)

type UnsmartCode

type UnsmartCode struct {
	// contains filtered or unexported fields
}

func (*UnsmartCode) Init added in v0.0.4

func (n *UnsmartCode) Init() (err error)

func (*UnsmartCode) Run

func (n *UnsmartCode) Run(root *html.Node, log ilog.Logger) (err error)

type WalkFunc

type WalkFunc func(srv *drive.Service, path string, info *drive.File, err error) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL