Documentation ¶
Index ¶
- Constants
- Variables
- func GetLinksFromFile(filePath string, content string) (links []LinkInfo, images []LinkInfo)
- func GetLinksFromMD(content string) (links []ContentLink, images []ContentLink)
- func GetTestFileSys() (fs fstest.MapFS, links map[string][]LinkInfo, ...)
- func ReplaceLinks(fPath string, fileContent []byte, moves []MovedLink) []byte
- type ContentLink
- type Empty
- type LinkInfo
- type LinkSyncer
- func (s *LinkSyncer) AddFile(relativePath string)
- func (s *LinkSyncer) AddPath(path string)
- func (s *LinkSyncer) Close()
- func (s *LinkSyncer) MoveFile(oldPath, newPath string, moves map[string]string)
- func (s *LinkSyncer) ProcessFiles() time.Duration
- func (s *LinkSyncer) ReadFile(filePath string) ([]byte, error)
- func (s LinkSyncer) RefsNum() int
- func (s *LinkSyncer) RemoveFile(relativePath string)
- func (s *LinkSyncer) Scan()
- func (s LinkSyncer) SourcesNum() int
- func (s *LinkSyncer) StartFileWatcher(interval time.Duration)
- func (s *LinkSyncer) StopEventListeners()
- func (s *LinkSyncer) StopFileWatcher()
- func (s *LinkSyncer) Sync(moves map[string]string)
- func (s *LinkSyncer) UpdateFile(relativePath string)
- func (s *LinkSyncer) UpdateLinksInFile(relativePath string, movedLinks []MovedLink) error
- func (s *LinkSyncer) Watch(interval time.Duration)
- func (s *LinkSyncer) WatchEvents(onMoves func(moves map[string]string))
- type MovedLink
Constants ¶
const MaxFileSize int64 = 1024 * 1024
Variables ¶
var ExcludedDirs = map[string]bool{"node_modules": true}
var ImgExtensions = ".png|.jpg|.jpeg|.webp|.svg|.tiff|.tff|.gif"
var ParsableFilesExtension = ".md"
Functions ¶
func GetLinksFromFile ¶
Extracts links from a file's content. filePath argument should be absolute.
func GetLinksFromMD ¶
func GetLinksFromMD(content string) (links []ContentLink, images []ContentLink)
func GetTestFileSys ¶
Types ¶
type ContentLink ¶
type ContentLink 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) 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))