syncer

package
v0.0.0-...-d07a634 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxFileSize int64 = 1024 * 1024

Variables

View Source
var ExcludedDirs = map[string]bool{"node_modules": true}
View Source
var ImgExtensions = ".png|.jpg|.jpeg|.webp|.svg|.tiff|.tff|.gif"
View Source
var ParsableFilesExtension = ".md"

Functions

func GetLinksFromFile

func GetLinksFromFile(filePath string, content string) (links []LinkInfo, images []LinkInfo)

Extracts links from a file's content. filePath argument should be absolute.

func GetLinksFromMD

func GetLinksFromMD(content string) (links []ContentLink, images []ContentLink)

func GetTestFileSys

func GetTestFileSys() (fs fstest.MapFS, links map[string][]LinkInfo, wasLinked map[string]map[string]Empty)
func ReplaceLinks(fPath string, fileContent []byte, moves []MovedLink) []byte

ReplaceLinks updates links in the file

Types

type ContentLink struct {
	// contains filtered or unexported fields
}

type Empty

type Empty struct{}

type LinkInfo

type LinkInfo struct {
	// contains filtered or unexported fields
}

type LinkSyncer

type LinkSyncer struct {
	Sources     map[string][]LinkInfo       // watching files
	Linked      map[string]map[string]Empty // map linked file paths to their source files
	MaxFileSize int64                       // max file size in bytes for parsable files

	Watcher fswatcher.FsWatcher
	// contains filtered or unexported fields
}

func New

func New(fileSystem fs.FS, root string, logger log.Logger, options ...func(*LinkSyncer)) *LinkSyncer

Creates a new LinkSyncer

func (*LinkSyncer) AddFile

func (s *LinkSyncer) AddFile(relativePath string)

AddFile reads, parses and saves info about given file and its links

func (*LinkSyncer) AddPath

func (s *LinkSyncer) AddPath(path string)

func (*LinkSyncer) Close

func (s *LinkSyncer) Close()

func (*LinkSyncer) MoveFile

func (s *LinkSyncer) MoveFile(oldPath, newPath string, moves map[string]string)

MoveFile moves a file in the cache from `oldPath` to `newPath` and update links in the file's content. `moves` is a map of all moved files including linked files, it is used to correctly replace paths if source file and its links were moved simultaneously.

func (*LinkSyncer) ProcessFiles

func (s *LinkSyncer) ProcessFiles() time.Duration

ProcessFiles walks the file tree and adds valid files

func (*LinkSyncer) ReadFile

func (s *LinkSyncer) ReadFile(filePath string) ([]byte, error)

func (LinkSyncer) RefsNum

func (s LinkSyncer) RefsNum() int

func (*LinkSyncer) RemoveFile

func (s *LinkSyncer) RemoveFile(relativePath string)

RemoveFile removes a file and its linked files from the cache

func (*LinkSyncer) Scan

func (s *LinkSyncer) Scan()

func (LinkSyncer) SourcesNum

func (s LinkSyncer) SourcesNum() int

func (*LinkSyncer) StartFileWatcher

func (s *LinkSyncer) StartFileWatcher(interval time.Duration)

func (*LinkSyncer) StopEventListeners

func (s *LinkSyncer) StopEventListeners()

func (*LinkSyncer) StopFileWatcher

func (s *LinkSyncer) StopFileWatcher()

func (*LinkSyncer) Sync

func (s *LinkSyncer) Sync(moves map[string]string)

Sync receives a map of moved files (from->to) and synchronize files, by updating links in notes and updating cache.

func (*LinkSyncer) UpdateFile

func (s *LinkSyncer) UpdateFile(relativePath string)

func (*LinkSyncer) UpdateLinksInFile

func (s *LinkSyncer) UpdateLinksInFile(relativePath string, movedLinks []MovedLink) error

UpdateLinksInFile replaces links in the file

func (*LinkSyncer) Watch

func (s *LinkSyncer) Watch(interval time.Duration)

func (*LinkSyncer) WatchEvents

func (s *LinkSyncer) WatchEvents(onMoves func(moves map[string]string))
type MovedLink struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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