importer

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	Substack  = "substack"
	Ghost     = "ghost"
	WordPress = "wordpress"
)

The platforms an export comes from.

View Source
const (
	Public  = "public"
	Members = "members"
)

Visibility levels, as website posts have them.

View Source
const (
	ProblemEmbed     = "embed_link"
	ProblemAlt       = "image_alt"
	ProblemImage     = "image_failed"
	ProblemShortcode = "shortcode"
)

Problem codes the converter reports.

View Source
const (
	// MaxPosts is the most posts one import takes.
	MaxPosts = 10000
)

Limits of an export.

Variables

View Source
var ErrNotExport = errors.New("not a Substack, Ghost or WordPress export")

ErrNotExport is a file that isn't a Substack, Ghost or WordPress export.

View Source
var ErrTooManyPosts = errors.New("more posts than one import takes")

ErrTooManyPosts is an export with more than MaxPosts posts.

Functions

func Detect

func Detect(data []byte) (string, error)

Detect names the platform an export comes from, by its content.

func File

func File(data []byte, p string) ([]byte, bool)

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 Images

func Images(fragment string) []string

Images lists the images Convert would rewrite, in order, each once.

func LegacyKey

func LegacyKey(p, rawQuery string) string

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".

func Name

func Name(source string) string

Name is a platform's name ("Substack"), the same in every language.

func Summary

func Summary(fragment string) string

Summary is the text an excerpt can be made of when the export has none: the post's first paragraph that has text.

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 Parse

func Parse(source string, data []byte) ([]Post, error)

Parse reads the posts of an export from a platform (as Detect named it).

func ParseGhost

func ParseGhost(data []byte) ([]Post, error)

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

func ParseSubstack(data []byte) ([]Post, error)

ParseSubstack reads a Substack export zip. Threads and pages aren't posts; a row without its HTML file has no body to import.

func ParseWXR

func ParseWXR(data []byte) ([]Post, error)

ParseWXR reads a WordPress export. Published posts, drafts and posts waiting (pending, scheduled) come in; private, password-protected and trashed ones stay out, as do pages, attachments and menus.

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

func Convert(fragment string, rewrite func(src string) (string, bool)) (string, []Problem)

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.

func ConvertIn

func ConvertIn(l i18n.Lang, fragment string, rewrite func(src string) (string, bool)) (string, []Problem)

ConvertIn is Convert with the embed links worded in l, the site's language.

Jump to

Keyboard shortcuts

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