platforms

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FrontMatterMappings = map[string]string{
	"title":         "title",
	"date":          "date",
	"date_updated":  "lastmod",
	"description":   "description",
	"categories":    "categories",
	"tags":          "tags",
	"canonical_url": "canonicalURL",
	"managed":       "managedByCrossBlogger"}

This is more just a set of defaults compatible with Hugo's frontmatter

Functions

func Load

func Load(sources interface{}, destinations interface{}, selectedSources []string, selectedDestinations []string) ([]Source, []Destination, error)

Load a slice of Destinations and Sources from values passed which the calling module shoukd have read from config If selectedDestinations is empty or nil, all destinations are loaded

Types

type Blogger

type Blogger struct {
	Name           string
	BlogUrl        string
	CategoryPrefix string
	// https://developers.google.com/blogger/docs/3.0/reference/posts/delete
	Overwrite               bool
	GenerateLlmDescriptions bool
	// contains filtered or unexported fields
}

func (Blogger) Authorize

func (b Blogger) Authorize(clientId string, clientSecret string, providedRefreshToken string) (string, string, error)

Return the access token, refresh token (if one was not provided), and an error (if one occurred). The access and refresh tokens are only returned if an error did not occur. In Google Cloud, create OAuth client credentials for a desktop app and enable the Blogger API.

func (Blogger) CleanMarkdownPosts

func (b Blogger) CleanMarkdownPosts(wg *sync.WaitGroup, interval time.Duration, markdownDest *Markdown, options PushPullOptions, errChan chan<- error)

Go through the contentDir of the Markdown struct and delete any posts that are not in the list of known posts. Only delete them if Frontmatter.Managed is true, however.

func (Blogger) GetBlogId

func (b Blogger) GetBlogId(accessToken string) (string, error)

Get the blog ID from the blog URL property of the Blogger struct.

func (Blogger) GetName

func (b Blogger) GetName() string

func (Blogger) GetType

func (b Blogger) GetType() string

func (Blogger) Pull

func (b Blogger) Pull(options PushPullOptions) (PostData, error)

Pull the post from the blog and return the post data.

func (Blogger) Push

func (b Blogger) Push(data PostData, options PushPullOptions) error

Push PostData to the blog.

func (*Blogger) Watch

func (b *Blogger) Watch(wg *sync.WaitGroup, interval time.Duration, options PushPullOptions, postChan chan<- PostData, errChan chan<- error)

Every interval, check for new posts (posts that haven't been seen before) and send them to the postChan channel.

type Destination

type Destination interface {
	Push(PostData, PushPullOptions) error
	GetName() string
	GetType() string
}

func CreateDestination

func CreateDestination(destMap map[string]interface{}) (Destination, error)

type Frontmatter

type Frontmatter struct {
	// TOOD: make frontmatter mappings configurable, somehow
	Title        string
	Date         string
	DateUpdated  string
	Description  string
	Categories   []string
	Tags         []string
	CanonicalUrl string
	Managed      bool
}

func FrontmatterFromMap

func FrontmatterFromMap(m map[string]interface{}, frontmatterMapping FrontmatterMapping) (*Frontmatter, error)

Take a map and return a Frontmatter struct, taking FrontmatterMapping into account

func (*Frontmatter) ToMap

func (f *Frontmatter) ToMap(frontmatterMapping FrontmatterMapping) map[string]interface{}

Take a Frontmatter struct and taking FrontmatterMapping into account, return a map ready to be marshaled into YAML

type FrontmatterMapping

type FrontmatterMapping struct {
	Title        string
	Date         string
	LastUpdated  string
	Description  string
	Categories   string
	Tags         string
	CanonicalURL string
	Managed      string
}

func FrontmatterMappingFromInterface

func FrontmatterMappingFromInterface(m interface{}) (*FrontmatterMapping, error)

Convert a frontmatter_mapping (interface{} due to how Viper works) to a FrontmatterMapping struct

type Markdown

type Markdown struct {
	Name string
	// ContentDir, for retrieving, should only be used if treating the passed post path as relative results in no file found
	ContentDir string
	GitDir     string
	// Example: []string{"title", "date", "lastmod", "canonicalURL"}
	FrontmatterMapping
	Overwrite bool
}

func (Markdown) Commit

func (m Markdown) Commit(slug string, push bool) (hash string, err error)

Commit and optionally push the changes to the Git repository. If contentDir is not a subdirectory of the gitDir, error.

func (Markdown) GetName

func (m Markdown) GetName() string

func (Markdown) GetType

func (m Markdown) GetType() string

func (Markdown) ParseMarkdown

func (m Markdown) ParseMarkdown(markdown string) (markdownWithoutFrontmatter string, html string, frontmatterObject *Frontmatter, err error)

func (Markdown) Pull

func (m Markdown) Pull(options PushPullOptions) (PostData, error)

func (Markdown) Push

func (m Markdown) Push(data PostData, options PushPullOptions) error

Push the data to the contentdir with the title as the filename using gosimple/slug. The markdown file should have YAML frontmatter compatible with Hugo.

type PostData

type PostData struct {
	Title       string
	Html        string
	Markdown    string
	Date        time.Time
	DateUpdated time.Time
	Description string
	Categories  []string
	Tags        []string
	// Other fields that are probably needed are canonical URL, publish date, and description
	CanonicalUrl string
}

type PushPullOptions

type PushPullOptions struct {
	AccessToken  string
	BlogId       string
	PostUrl      string
	Filepath     string
	RefreshToken string
	ClientId     string
	ClientSecret string
	LlmProvider  string
	LlmBaseUrl   string
	LlmApiKey    string
	LlmModel     string
}

type Source

type Source interface {
	Pull(PushPullOptions) (PostData, error)
	GetName() string
	GetType() string
}

func CreateSource

func CreateSource(sourceMap map[string]interface{}) (Source, error)

type WatchableSource

type WatchableSource interface {
	Source
	// Watch(time.Duration, PushPullOptions, chan<- PostData, chan<- error)
	Watch(*sync.WaitGroup, time.Duration, PushPullOptions, chan<- PostData, chan<- error)
	CleanMarkdownPosts(*sync.WaitGroup, time.Duration, *Markdown, PushPullOptions, chan<- error)
}

Jump to

Keyboard shortcuts

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