Documentation
¶
Overview ¶
Package importer reads the exports of other platforms into posts and converts their HTML into the MJML a ReputeCast post holds (M61, G-26):
- a Substack export, the zip with posts.csv and posts/<post_id>.html;
- a Ghost export, the JSON file (or a zip holding it, with the site's content/images when the zip has them);
- a WordPress export, the WXR file (WordPress eXtended RSS).
The format is told from the content, never from the file's name. It touches no database: internal/website stages the posts, and imports them.
Index ¶
Constants ¶
const ( Substack = "substack" Ghost = "ghost" WordPress = "wordpress" )
The platforms an export comes from.
const ( Public = "public" Members = "members" Paid = "paid" )
Visibility levels, as website posts have them.
const ( ProblemEmbed = "embed_link" ProblemAlt = "image_alt" ProblemImage = "image_failed" ProblemShortcode = "shortcode" )
Problem codes the converter reports.
const (
// MaxPosts is the most posts one import takes.
MaxPosts = 10000
)
Limits of an export.
Variables ¶
var ErrNotExport = errors.New("not a Substack, Ghost or WordPress export")
ErrNotExport is a file that isn't a Substack, Ghost or WordPress export.
var ErrTooManyPosts = errors.New("more posts than one import takes")
ErrTooManyPosts is an export with more than MaxPosts posts.
Functions ¶
func File ¶
File is a file the export holds at path (a Ghost zip's content/images/2024/05/photo.jpg for "/content/images/2024/05/photo.jpg"), so an image of a site the export can't name the address of can still be copied. ok is false when the export isn't a zip or has no such file.
func LegacyKey ¶
LegacyKey is how an old address is kept and looked up: lower case, without the slashes around it; "?p=<id>" (WordPress's own links) keeps its query, as "?p=123".
Types ¶
type Post ¶
type Post struct {
// SourceID is the platform's id of the post: Substack's post_id,
// Ghost's id, WordPress's wp:post_id.
SourceID string
Title string
Slug string
PublishedAt *time.Time
// Draft: not published on the old site (a draft, scheduled, pending).
Draft bool
Visibility string
// TierRefs are the old site's tiers that could read a paid post, by
// name ("Paid subscribers", a Ghost tier's name); empty: every paid
// member.
TierRefs []string
Tags []string
Author string
// Excerpt is the platform's own (Substack's subtitle), as text.
Excerpt string
CoverURL string
CoverAlt string
// SEO and the canonical address.
SEOTitle, SEODescription, CanonicalURL string
// SourceURL is the post's address on the old site: absolute when the
// export says where the site is, else its path.
SourceURL string
// LegacyPaths are the old site's addresses of the post, as LegacyKey
// makes them ("p/my-post", "my-old-slug", "?p=123").
LegacyPaths []string
HTML string
}
Post is a post as an export has it.
func ParseGhost ¶
ParseGhost reads a Ghost export: the JSON, or a zip holding it. Pages aren't posts. Links and images to the site itself become root-relative ("/my-post/", "/content/images/…"): on the site's own domain the old addresses lead to the imported posts, and a zip's images are copied.
func ParseSubstack ¶
ParseSubstack reads a Substack export zip. Threads and pages aren't posts; a row without its HTML file has no body to import.
type Problem ¶
type Problem struct {
Code string `json:"code"`
// Detail is what it is about: the platform of an embed, an image's
// address, a shortcode's name, the tags left out, a new address.
Detail string `json:"detail,omitempty"`
}
Problem is something about a post the import couldn't keep as it was: an embed shown as a link, an image without alt text.
func Convert ¶
Convert writes a post's HTML as a web post's MJML: text (paragraphs, headings, lists, quotes, code, tables, captioned figures) in mj-text blocks, cleaned by the site's own allowlist (render.Sanitize); each image an mj-image, its src through rewrite (false keeps it and reports it), an empty alt reported; hr an mj-divider; buttons mj-button. An embed (YouTube, Vimeo, X, Instagram, Spotify, a Substack or Ghost card) becomes a paragraph linking to it, reported. A paywall marker (Substack's paywall-jump, Ghost's <!--members-only-->) becomes the free preview marker between blocks. Liquid in the text is written as entities, so "{{" stays text. The links' words are English; ConvertIn picks the language.