wfimport

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MPL-2.0 Imports: 11 Imported by: 2

README

import

libraries for parsing and importing posts from various source files

usage

import wfimport "github.com/writeas/import"

See GoDoc for details https://godoc.org/github.com/writeas/import

Documentation

Overview

Package wfimport provides library functions for parsing and importing writefreely posts from various files. https://github.com/writeas/writefreely

Status

Current support is for files, directories and zip archives. Support is planned for exported data from Medium, Ghost, Wordpress and writefreely exports in zip or json.

About Posts

In the context of this package a post is actually referring to a PostParams from https://github.com/writeas/go-writeas.

// PostParams holds values for creating or updating a post.
PostParams struct {
	// Parameters only for updating
	ID    string `json:"-"`
	Token string `json:"token,omitempty"`

	// Parameters for creating or updating
	Slug     string     `json:"slug"`
	Created  *time.Time `json:"created,omitempty"`
	Updated  *time.Time `json:"updated,omitempty"`
	Title    string     `json:"title,omitempty"`
	Content  string     `json:"body,omitempty"`
	Font     string     `json:"font,omitempty"`
	IsRTL    *bool      `json:"rtl,omitempty"`
	Language *string    `json:"lang,omitempty"`

	// Parameters only for creating
	Crosspost []map[string]string `json:"crosspost,omitempty"`

	// Parameters for collection posts
	Collection string `json:"-"`
}

Index

Constants

View Source
const (
	// DraftsKey is the key for all parsed draft posts in a ZipCollections map
	DraftsKey = "drafts"
)

Variables

View Source
var (
	// ErrEmptyFile is returned when the file is empty
	ErrEmptyFile = errors.New("file is empty")
	// ErrInvalidContentType is returned when the detected content type does
	// not match text/* as per net/http.DetectContentType
	ErrInvalidContentType = errors.New("invalid content type")
	// ErrEmptyDir is returned when the directory is empty
	ErrEmptyDir = errors.New("directory is empty")
)

Functions

func FromDirectory

func FromDirectory(path string) ([]*writeas.PostParams, error)

FromDirectory reads all text and markdown files in path and returns the parsed posts and an error if any.

func FromDirectoryMatch

func FromDirectoryMatch(path, pattern string) ([]*writeas.PostParams, error)

FromDirectoryMatch reads all text and markdown files in path that match the pattern returning the parsed posts and an error if any.

The pattern should be a valid regex, for more details see https://golang.org/s/re2syntax or run `go doc regexp/syntax`

func FromFile

func FromFile(path string) (*writeas.PostParams, error)

FromFile reads in a file from path and returns the parsed post and an error if any. The title will be extracted from the first markdown level 1 header.

func FromZip

func FromZip(archive string) ([]*writeas.PostParams, error)

FromZip opens a zip archive and returns a slice of *writeas.PostParams and an error if any. It only reads the top level of the archive tree.

func FromZipByFunc

func FromZipByFunc(archive string, f ZipFunc) ([]*writeas.PostParams, error)

FromZipByFunc opens an archive and filters the contents according to the passed ZipFunc. It returns a slice of writeas.PostParams and any error.

func TextFileZipFunc added in v0.1.3

func TextFileZipFunc(f *zip.File) (*writeas.PostParams, error)

TextFileZipFunc parses .txt files into PostParams

func TopLevelZipFunc

func TopLevelZipFunc(f *zip.File) (*writeas.PostParams, error)

TopLevelZipFunc returns a pointer to a writeas.PostParams for any parseable zip.File that is not a directory. It does not traverse children.

This is an example of a ZipFunc that can be used to filter files parse from a zip archive.

Types

type ZipCollections

type ZipCollections map[string][]*writeas.PostParams

ZipCollections holds a map of collections of post params. The keys are the collection name, parsed from the directory structure. Draft posts are included under the key drafts, those that were top level files in the archive.

func FromZipDirs

func FromZipDirs(archive string) (ZipCollections, error)

FromZipDirs opens a zip archive and returns a map of post collections and an error if any.

The map is of [string][]*writeas.PostParams where the string key is the name of the directory. The top level directory posts will be 'drafts'.

func FromZipDirsByFunc

func FromZipDirsByFunc(archive string, f ZipFunc) (ZipCollections, error)

FromZipDirsByFunc works as FromZipDirs but filtering files through f.

type ZipFunc

type ZipFunc func(f *zip.File) (*writeas.PostParams, error)

ZipFunc should return a pointer to a writeas.PostParams for any zip.File that meets criteria. It is used in FromZipFunc to filter the archives files.

For an example, see the file zip_funcs.go

Jump to

Keyboard shortcuts

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