internal

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedOpenGraph = errors.New("failed to open graph")
View Source
var ErrInvalidResponseStatus = errors.New("invalid response status")
View Source
var ErrMissingConfig = errors.New("LOGSEQ_API_TOKEN and LOGSEQ_HOST_URL must be set")
View Source
var ErrPageIsNil = errors.New("page is nil")

ErrPageIsNil is returned when a page is nil.

View Source
var PageColor = color.New(color.FgHiWhite).SprintfFunc() //nolint:gochecknoglobals

PageColor is a color function for page names.

Functions

func AddTask

func AddTask(opts *AddTaskOptions) error

AddTask adds a task to Logseq. If Key is provided, it searches for an existing task containing that key (case-insensitive) and updates it. Otherwise, creates a new task. If Page is provided, adds to that page. Otherwise, adds to journal for Date. If BlockText is provided, adds as a child of the first block containing that text.

func AppendRawMarkdownToJournal

func AppendRawMarkdownToJournal(graph *logseq.Graph, date time.Time,
	rawMarkdown string) (int, error)

AppendRawMarkdownToJournal appends raw Markdown content to the journal page for the given date. I tried appending blocks with `logseq-go` but there is and with text containing brackets. e.g. "[something]" is escaped like "\[something\]" and this breaks links.

func DateYYYYMMDD

func DateYYYYMMDD(time time.Time) int

DateYYYYMMDD returns the current date in YYYYMMDD format.

func FindBlockContainingText

func FindBlockContainingText(page logseq.Page, searchText string) *content.Block

FindBlockContainingText searches for the first block containing the specified text using FindDeep.

func FindTaskMarkerByKey added in v0.7.0

func FindTaskMarkerByKey(page logseq.Page, parentBlock *content.Block, key string) *content.TaskMarker

FindTaskMarkerByKey searches for a task marker containing the specified key (case-insensitive). If parentBlock is provided, searches only among its children. Otherwise, searches in the entire page. Returns the TaskMarker if found, nil otherwise.

func InsertMarkdownToJournal

func InsertMarkdownToJournal(opts *InsertMarkdownOptions) error

InsertMarkdownToJournal inserts markdown content to a journal page If ParentText is provided, it searches for the first block containing that text and inserts the content as a child block. Otherwise, appends to the end.

func IsAncestor

func IsAncestor(block, ancestor *content.Block) bool

IsAncestor checks if ancestor is an ancestor of block by traversing up the parent chain. Returns true if ancestor is found in the parent hierarchy of block, false otherwise. Returns true if block and ancestor are the same block.

func IsValidMarkdownFile

func IsValidMarkdownFile(filePath string) bool

IsValidMarkdownFile checks if a file is a Markdown file, by looking at its extension, not its content.

func OpenGraphFromPath

func OpenGraphFromPath(path string) *logseq.Graph

OpenGraphFromPath opens a Logseq graph (from the path provided when the instance was created). It doesn't return an error and aborts the program if it fails because it's an internal function. This is done on purpose to avoid error handling boilerplate code throughout the package.

func OpenPage

func OpenPage(graph *logseq.Graph, pageTitle string) logseq.Page

OpenPage opens a page in the Logseq graph. It aborts the program in case of error because it's an internal function. Also, it's not common to have errors when opening a page.

func ReadFromStdin

func ReadFromStdin() string

ReadFromStdin reads from stdin and returns the content as a string. It doesn't return an error and aborts the program if it fails because it's an internal function.

func SortAndRemoveDuplicates

func SortAndRemoveDuplicates(elements []string) []string

func TidyUpOneFile

func TidyUpOneFile(graph *logseq.Graph, path string) int

Types

type AddTaskOptions

type AddTaskOptions struct {
	Graph     *logseq.Graph
	Date      time.Time
	Page      string           // Page name to add the task to (empty = journal)
	BlockText string           // Partial text to search for in parent blocks
	Key       string           // Unique key to search for existing task (case-insensitive)
	Name      string           // Short name of the task
	TimeNow   func() time.Time // For testing
}

AddTaskOptions contains options for adding a task to Logseq.

type CategorizedTasks

type CategorizedTasks struct {
	All             *set.Set[string]
	Overdue         *set.Set[string]
	Doing           *set.Set[string]
	FutureScheduled *set.Set[string]
}

func NewCategorizedTasks

func NewCategorizedTasks() CategorizedTasks

type ChangedContents

type ChangedContents struct {
	Msg         string
	NewContents string
}

ChangedContents is the result of a check function that modifies file contents directly without a transaction.

func RemoveUnnecessaryBracketsFromTags

func RemoveUnnecessaryBracketsFromTags(oldContents string) ChangedContents

RemoveUnnecessaryBracketsFromTags removes unnecessary brackets from hashtags. logseq-go rewrites tags correctly when saving the transaction, removing unnecessary brackets. But, when reading the file, the AST doesn't provide the information if a tag has brackets or not. So I would have to rewrite the file to fix them, and I don't want to do it every time there is a tag without spaces. Also, as of 2024-12-30, logseq-go has a bug when reading properties with spaces in values, which causes them to be partially removed from the file, destroying data. I will report it soon.

type ChangedPage

type ChangedPage struct {
	Msg     string
	Changed bool
}

ChangedPage is the result of a check function that modifies Markdown through a Page and a transaction.

func CheckForbiddenReferences

func CheckForbiddenReferences(page logseq.Page) ChangedPage

CheckForbiddenReferences checks if a page has forbidden references to other pages or tags.

func CheckRunningTasks

func CheckRunningTasks(page logseq.Page) ChangedPage

CheckRunningTasks checks if a page has running tasks (DOING, etc.).

func RemoveDoubleSpaces

func RemoveDoubleSpaces(page logseq.Page) ChangedPage

RemoveDoubleSpaces removes double spaces from text, page links, and tags, except for tables.

func RemoveEmptyBullets

func RemoveEmptyBullets(page logseq.Page) ChangedPage

type InsertMarkdownOptions

type InsertMarkdownOptions struct {
	Graph      *logseq.Graph
	Date       time.Time
	Content    string
	ParentText string // Partial text to search for in parent blocks
}

InsertMarkdownOptions contains options for inserting markdown content.

type LogseqAPI

type LogseqAPI interface {
	PostQuery(query string) (string, error)
}

func NewLogseqAPI

func NewLogseqAPI(path, hostURL, apiToken string) LogseqAPI

NewLogseqAPI creates a new LogseqAPI instance.

type LogseqFinder

type LogseqFinder interface {
	FindFirstQuery(pageTitle string) string
}

func NewLogseqFinder

func NewLogseqFinder(graph *logseq.Graph) LogseqFinder

type TaskJSON

type TaskJSON struct {
	UUID      string   `json:"uuid"`
	Marker    string   `json:"marker"`
	Content   string   `json:"content"`
	Page      pageJSON `json:"page"`
	Deadline  int      `json:"deadline"`
	Scheduled int      `json:"scheduled"`
}

func ExtractTasksFromJSON

func ExtractTasksFromJSON(jsonStr string) ([]TaskJSON, error)

func (TaskJSON) Doing

func (t TaskJSON) Doing() bool

Doing checks if the task has the DOING marker.

func (TaskJSON) FutureScheduled

func (t TaskJSON) FutureScheduled(currentTime func() time.Time) bool

FutureScheduled checks if the task is scheduled for the future (tomorrow onwards) and it's not overdue.

func (TaskJSON) Overdue

func (t TaskJSON) Overdue(currentTime func() time.Time) bool

Overdue checks if the task is overdue based on deadline or scheduled date.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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