Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertBlocks ¶
ConvertBlocks converts WordPress block-editor HTML into a TipTap JSON document string. imageMap remaps WordPress image URLs to local media URLs; entries not present in the map keep their original URL. Unsupported blocks degrade to a plain paragraph so no content is silently lost.
func ExtractImageURLs ¶
ExtractImageURLs scans WordPress block HTML and returns every image source URL found (img src, plus cover/gallery background URLs in block attrs). The importer uses this to know which media to download before conversion.
Types ¶
type ImportResult ¶
type ImportResult struct {
Imported int `json:"imported"`
Skipped int `json:"skipped"`
Errors []string `json:"errors,omitempty"`
}
ImportResult summarizes the outcome of an import run.
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer orchestrates a WordPress import: parse the WXR, download images, convert each item to TipTap JSON, and create it via the content service.
func NewImporter ¶
func NewImporter(contentService contentCreator, downloader *MediaDownloader, logger *util.Logger) *Importer
NewImporter creates an importer.
func (*Importer) Import ¶
func (imp *Importer) Import(ctx context.Context, wxrData io.Reader, userID int) (*ImportResult, error)
Import reads a WXR stream and imports every post and page. Image download failures are logged and recorded but never abort the run; the original WordPress URL is kept as a fallback. Returns an aggregated result.
type MediaDownloader ¶
type MediaDownloader struct {
// contains filtered or unexported fields
}
MediaDownloader downloads images from a WordPress site and re-uploads them through the media service (which converts to WebP, deduplicates by hash, and generates thumbnails). Results are cached per URL so each image is fetched at most once per import.
func NewMediaDownloader ¶
func NewMediaDownloader(httpClient *http.Client, mediaService mediaService) *MediaDownloader
NewMediaDownloader creates a downloader. If httpClient is nil a default client with a 30-second timeout is used.
func (*MediaDownloader) DownloadAndUpload ¶
func (d *MediaDownloader) DownloadAndUpload(ctx context.Context, imageURL string, userID int) (string, error)
DownloadAndUpload fetches the image at imageURL and re-uploads it to local storage. Returns the local media URL. Non-image URLs and failed downloads return an empty string and nil error so the caller can fall back to the original WordPress URL without aborting the import.
type ParsedItem ¶
type ParsedItem struct {
Title string
Content string
Slug string
Status string // mapped to "published" or "draft"
PostType string // "post" or "page"
Tags []string
PubDate string
}
ParsedItem is a normalized WordPress item ready for conversion.
type WXRDocument ¶
type WXRDocument struct {
SiteTitle string
SiteURL string
Items []ParsedItem
}
WXRDocument is the parsed, normalized representation of a WXR export. Only post and page items are retained; other post types (attachment, wp_navigation, wp_global_styles, revisions) are filtered out during parsing.
func Parse ¶
func Parse(r io.Reader) (*WXRDocument, error)
Parse reads a WordPress eXtended RSS (WXR) stream and returns a normalized document containing only post and page items. Statuses are mapped to the Lesstruct vocabulary ("publish" → "published", everything else → "draft"). Tags are collected from item-level category elements with domain "post_tag" or "category".