lj

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountComments added in v0.2.1

func CountComments(comments []*Comment) int

CountComments returns the total number of comments in a tree (including nested children).

func FetchFullPostIndex added in v0.2.0

func FetchFullPostIndex(ctx context.Context, client *Client, user string) ([]int, error)

FetchFullPostIndex returns all post IDs by iterating monthly archive pages. This catches old posts that FetchPostIndex misses due to LJ index page limits.

func FetchPostIndex

func FetchPostIndex(ctx context.Context, client *Client, user string) ([]int, error)

FetchPostIndex returns all post LJ IDs in chronological order (oldest first).

func FindFirstPostID

func FindFirstPostID(ctx context.Context, client *Client, user string) (int, error)

FindFirstPostID returns the ID of the oldest post in the journal. Uses exponential search + binary search on post URLs.

func FindLastPostID

func FindLastPostID(ctx context.Context, client *Client, user string) (int, error)

FindLastPostID returns the ID of the newest post in the journal.

func HTMLToMarkdown

func HTMLToMarkdown(html string) string

HTMLToMarkdown converts HTML to Markdown. Handles the subset of HTML found in LiveJournal posts: p, br, b/strong, i/em, a, img, blockquote, ul/ol/li, h1-h6.

func ParseDate

func ParseDate(s string) time.Time

func ParseJournal

func ParseJournal(ctx context.Context, client *Client, user string, comments bool, onPost func(*Post) error) error

ParseJournal fetches all posts from a journal, calling onPost for each.

func ParseJournalIndex

func ParseJournalIndex(body io.Reader) ([]int, error)

ParseJournalIndex extracts post IDs from a journal index page HTML.

func ParsePostURL

func ParsePostURL(rawURL string) (user string, id int, err error)

func ParseProfileStats

func ParseProfileStats(ctx context.Context, client *Client, user string) (int, error)

ParseProfileStats fetches the profile page and returns journal entry count.

Types

type Client

type Client struct {
	Log        func(format string, args ...any) // progress logger, nil = silent
	BodyFormat string                           // "html" (default), "markdown", "text"
	ImagesDir  string                           // download images to this dir, empty = skip
	SkipIDs    map[int]bool                     // skip these post IDs (for resume)
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, url, destPath string) error

DownloadFile downloads a URL to a local file. Skips if file already exists.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, url string) (bool, error)

Exists checks if a URL returns 200 without reading the body.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (*http.Response, error)

type Comment

type Comment struct {
	ID       int        `json:"id"`
	TalkID   int        `json:"talk_id"`
	ParentID int        `json:"parent_id"`
	Level    int        `json:"level"`
	Author   string     `json:"author"`
	Username string     `json:"username"`
	Date     string     `json:"date"`
	DateUnix int64      `json:"date_unix"`
	Body     string     `json:"body"`
	Subject  string     `json:"subject,omitempty"`
	Userpic  string     `json:"userpic,omitempty"`
	Deleted  bool       `json:"deleted,omitempty"`
	Children []*Comment `json:"children,omitempty"`
}

func BuildCommentTree

func BuildCommentTree(flat []*Comment) []*Comment

func ParseComments

func ParseComments(ctx context.Context, client *Client, user string, id int) ([]*Comment, error)

type OGMeta

type OGMeta struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Image       string `json:"image,omitempty"`
}

type Post

type Post struct {
	ID       int        `json:"id"`
	URL      string     `json:"url"`
	Title    string     `json:"title"`
	Date     string     `json:"date"`
	DateUnix int64      `json:"date_unix,omitempty"`
	Author   string     `json:"author"`
	Body     string     `json:"body"`
	Tags     []string   `json:"tags,omitempty"`
	OG       *OGMeta    `json:"og,omitempty"`
	Comments []*Comment `json:"comments,omitempty"`
}

func ParsePost

func ParsePost(ctx context.Context, client *Client, user string, id int) (*Post, error)

Jump to

Keyboard shortcuts

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