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
- Variables
- func FromDirectory(path string) ([]*writeas.PostParams, error)
- func FromDirectoryMatch(path, pattern string) ([]*writeas.PostParams, error)
- func FromFile(path string) (*writeas.PostParams, error)
- func FromZip(archive string) ([]*writeas.PostParams, error)
- func FromZipByFunc(archive string, f ZipFunc) ([]*writeas.PostParams, error)
- func TextFileZipFunc(f *zip.File) (*writeas.PostParams, error)
- func TopLevelZipFunc(f *zip.File) (*writeas.PostParams, error)
- type ZipCollections
- type ZipFunc
Constants ¶
const (
// DraftsKey is the key for all parsed draft posts in a ZipCollections map
DraftsKey = "drafts"
)
Variables ¶
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 ¶
FromDirectory reads all text and markdown files in path and returns the parsed posts and an error if any.
func FromDirectoryMatch ¶
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 ¶
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 ¶
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 ¶
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
TextFileZipFunc parses .txt files into PostParams
func TopLevelZipFunc ¶
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.