Documentation ¶
Index ¶
- Constants
- type Config
- func (c *Config) ApplyDefaults()
- func (c *Config) GetGhostPost(rows *sql.Rows) (GhostPost, error)
- func (c *Config) IsValid(p GhostPost) bool
- func (conf *Config) ParseTemplate() error
- func (c *Config) Process()
- func (c *Config) ProcessGhostPost(post GhostPost) (GhostPost, error)
- func (c *Config) ProcessHTML(s string) (string, error)
- func (c *Config) RenderAll(p []GhostPost) error
- func (c *Config) RenderOne(p GhostPost) (int, string, error)
- func (c *Config) RenderString(post GhostPost) (string, error)
- type FrontMatterConfig
- type GhostPost
- type PostTemplate
Constants ¶
const ( DefaultRawShortcodeStart = "{{< rawhtml >}}" DefaultRawShortcodeEnd = "{{</ rawhtml >}}" DefaultTemplate = `` /* 289-byte string literal not displayed */ )
Default values used in the config if not set.
const ( DefaultFrontMatterTitle = "title" DefaultFrontMatterDate = "date" DefaultFrontMatterSlug = "slug" DefaultFrontMatterDraft = "draft" )
Default value that is used for front matter in lieu of a user-configured value.
const GhostPostStatusDraft = "draft"
const QUERY_POSTS_FIELDS = `` /* 766-byte string literal not displayed */
All of the fields that map to GhostPost.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Connection string for the mysql database. MySQLConnectionString string `json:"mysqlConnectionString"` // Values to use for the front matter. FrontMatter FrontMatterConfig `json:"frontMatter"` // Your theme's shortcode that starts the output of raw html, such as: // "{{< rawhtml >}}" RawShortcodeStart string `json:"rawShortcodeStart"` // Your theme's shortcode that ends the output of raw html, such as: // "{{</ rawHtml >}}" RawShortcodeEnd string `json:"rawShortcodeEnd"` // Path to save rendered markdown files to. OutputPath string `json:"outputPath"` // All occurrences of __GHOST_URL__ will be replaced with this string - this // is required in order to make images work, as well as other things. GhostURL string `json:"ghostUrl"` // Values are typically "post": true or "page": true. PostTypes map[string]bool `json:"postTypes"` // Values are typically "published": true, "draft": false. // Depending on your setup, you may set "sent": false. PostStatuses map[string]bool `json:"postStatuses"` // Values are typically "public": true. PostVisibilities map[string]bool `json:"postVisibilities"` // If true, empty (null) posts will cause the program to halt. ForbidEmptyPosts bool `json:"forbidEmptyPosts"` // If true, posts without publication dates with be set to now. SetUnpublishedToNow bool `json:"setUnpublishedToNow"` // If true, all posts will not be marked as drafts. PublishDrafts bool `json:"publishDrafts"` // A mapping of strings to replace within <a href=""> tags. This will only // be done if ReplaceLinks is set to true (which will under normal // circumstances be determined if a non-zero length map is provided for // LinkReplacements, but if you are doing something abnormal, you should set // ReplaceLinks to true manually.) LinkReplacements map[string]string `json:"linkReplacements"` // The template that will be rendered. // // The front matter will be placed at the top of every page. Usage looks // like this: // // ` // --- // {{ .FrontMatterConfig.Title }}: {{ .Post.Title }} // {{ .FrontMatterConfig.Date }}: "{{ .Post.PublishedAt }}" // {{ .FrontMatterConfig.Draft }}: {{ .Post.IsDraft }} // customProperty: customValue # etc. // --- // // {{ .PostHtml }} // ` Template string `json:"template"` // If true, <a href=""> tags will have each key replaced with its respective // value. This is useful for swapping things like http://example.com with // https://nojs.example.com. // // Typically this gets set to true if using the // expected workflow for this program, but if you are doing something // out of the ordinary, please set this to true and then use the // LinkReplacements map to define link replacements. ReplaceLinks bool // contains filtered or unexported fields }
func LoadConfig ¶
LoadConfig reads from file f and applies sensible defaults to values not specifically set by the user.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults applies sensible defaults to the config if left unconfigured. You shouldn't normally need to execute this, because it's called automatically by LoadConfig.
func (*Config) GetGhostPost ¶
GetGhostPost parses an SQL row-yielding iterator and returns a GhostPost from it.
Usage:
rows, err := db.Query(fmt.Sprintf("SELECT %v FROM posts LIMIT 10", g2h.QUERY_POSTS_FIELDS))
if err != nil { log.Fatalf("failed to query posts from db: %v", err.Error()) } defer rows.Close() for rows.Next() { post, err := ghosttohugo.GetGhostPost(rows) if err != nil { // ... } }
func (*Config) IsValid ¶
IsValid returns true or false if the post meets the criteria for being rendered based on the user-provided configuration. This doesn't get called by any of the other Render functions - it's up to you if you want to perform any filtering at all.
This function does not do any checks regarding the published/draft state.
func (*Config) ParseTemplate ¶
ParseTemplate parses the user-configured template. This should only need to be run once.
func (*Config) Process ¶
func (c *Config) Process()
Process makes a few changes to the config based on the user-provided configuration. You shouldn't normally need to execute this, because it's called automatically by LoadConfig.
func (*Config) ProcessGhostPost ¶
ProcessGhostPost is called by [GetGhostPost] and fills in/processes fields that are required in order for this module to fulfill its intended purpose.
func (*Config) ProcessHTML ¶
ProcessHTML removes all height and width tags from an input xml string, as well as anything else needed in order to process the document.
type FrontMatterConfig ¶
type FrontMatterConfig struct { // The string to use instead of 'title' in front matter. Title string `json:"title"` // The string to use instead of 'date' in front matter. Date string `json:"date"` // The string to use instead of 'draft' in front matter. Draft string `json:"draft"` // https://gohugo.io/content-management/urls/#slug Slug string `json:"slug"` }
FrontMatterConfig determines what strings to use for various front matter values - for example, if FrontMatterConfig.Title is set to a value of "pageTitle", the front matter will be rendered like this:
` --- pageTitle: {{ Post.Title }} # ... --- `
func (*FrontMatterConfig) ApplyDefaults ¶
func (f *FrontMatterConfig) ApplyDefaults()
ApplyDefaults applies sensible defaults to the front matter config if left unconfigured. You shouldn't normally need to execute this, because it's called automatically by LoadConfig.
type GhostPost ¶
type GhostPost struct { ID string UUID string Title string Slug string Mobiledoc sql.NullString Lexical sql.NullString HTML sql.NullString CommentID sql.NullString Plaintext sql.NullString FeatureImage sql.NullString Featured bool Type string Status string Locale sql.NullString Visibility string EmailRecipientFilter string CreatedAt time.Time CreatedBy string UpdatedAt time.Time // sql.NullTime UpdatedBy sql.NullString PublishedAt time.Time // sql.NullTime PublishedBy sql.NullString CustomExcerpt sql.NullString CodeinjectionHead sql.NullString CodeinjectionFoot sql.NullString CustomTemplate sql.NullString CanonicalUrl sql.NullString NewsletterId sql.NullString ShowTitleAndFeatureImage bool // On the Go side, we need to parse these values before putting them into // the [GhostPost] struct. SqlCreatedAt string // time.Time // On the Go side, we need to parse these values before putting them into // the [GhostPost] struct. SqlUpdatedAt sql.NullString // sql.NullTime // On the Go side, we need to parse these values before putting them into // the [GhostPost] struct. SqlPublishedAt sql.NullString // sql.NullTime // This module parses the status field and determines if it's a draft. This // isn't specifically a boolean value in the database. It may not always // be accurate if Ghost has special logic that determines if something is // a draft or not. IsDraft bool }
GhostPost is the data type that exists in the mysql database as of Ghost v5.87.1.
type PostTemplate ¶
type PostTemplate struct { FrontMatterConfig FrontMatterConfig Post GhostPost PostDate string // Post's date rendered as a standard string PostHTML string RawShortcodeStart string RawShortcodeEnd string }
PostTemplate is what's passed to the template directly. Your configuration's template string can use any field from here. For example:
`{{ .Post.FeatureImage }}`