mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Support searching some plaintext assets content https://github.com/siyuan-note/siyuan/issues/8987
This commit is contained in:
parent
3b549f46f2
commit
89f85a93c4
1 changed files with 44 additions and 10 deletions
|
|
@ -290,8 +290,8 @@ func IndexAssetContent(absPath string) {
|
||||||
assetsDir := util.GetDataAssetsAbsPath()
|
assetsDir := util.GetDataAssetsAbsPath()
|
||||||
|
|
||||||
ext := strings.ToLower(filepath.Ext(absPath))
|
ext := strings.ToLower(filepath.Ext(absPath))
|
||||||
parser, found := assetContentSearcher.Parsers[ext]
|
parser := assetContentSearcher.GetParser(ext)
|
||||||
if !found {
|
if nil == parser {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,11 +352,17 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AssetsSearcher struct {
|
type AssetsSearcher struct {
|
||||||
Parsers map[string]AssetParser
|
parsers map[string]AssetParser
|
||||||
|
|
||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (searcher *AssetsSearcher) GetParser(ext string) AssetParser {
|
||||||
|
searcher.lock.Lock()
|
||||||
|
defer searcher.lock.Unlock()
|
||||||
|
|
||||||
|
return searcher.parsers[ext]
|
||||||
|
}
|
||||||
|
|
||||||
func (searcher *AssetsSearcher) FullIndex() {
|
func (searcher *AssetsSearcher) FullIndex() {
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
|
|
@ -377,8 +383,8 @@ func (searcher *AssetsSearcher) FullIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := strings.ToLower(filepath.Ext(absPath))
|
ext := strings.ToLower(filepath.Ext(absPath))
|
||||||
parser, found := searcher.Parsers[ext]
|
parser := searcher.GetParser(ext)
|
||||||
if !found {
|
if nil == parser {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -411,11 +417,39 @@ func (searcher *AssetsSearcher) FullIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAssetsSearcher() *AssetsSearcher {
|
func NewAssetsSearcher() *AssetsSearcher {
|
||||||
|
txtAssetParser := &TxtAssetParser{}
|
||||||
return &AssetsSearcher{
|
return &AssetsSearcher{
|
||||||
Parsers: map[string]AssetParser{
|
parsers: map[string]AssetParser{
|
||||||
".txt": &TxtAssetParser{},
|
".txt": txtAssetParser,
|
||||||
".md": &TxtAssetParser{},
|
".md": txtAssetParser,
|
||||||
".markdown": &TxtAssetParser{},
|
".markdown": txtAssetParser,
|
||||||
|
".json": txtAssetParser,
|
||||||
|
".log": txtAssetParser,
|
||||||
|
".sql": txtAssetParser,
|
||||||
|
".html": txtAssetParser,
|
||||||
|
".xml": txtAssetParser,
|
||||||
|
".java": txtAssetParser,
|
||||||
|
".h": txtAssetParser,
|
||||||
|
".c": txtAssetParser,
|
||||||
|
".cpp": txtAssetParser,
|
||||||
|
".go": txtAssetParser,
|
||||||
|
".swift": txtAssetParser,
|
||||||
|
".kt": txtAssetParser,
|
||||||
|
".py": txtAssetParser,
|
||||||
|
".js": txtAssetParser,
|
||||||
|
".css": txtAssetParser,
|
||||||
|
".ts": txtAssetParser,
|
||||||
|
".sh": txtAssetParser,
|
||||||
|
".bat": txtAssetParser,
|
||||||
|
".cmd": txtAssetParser,
|
||||||
|
".ini": txtAssetParser,
|
||||||
|
".yaml": txtAssetParser,
|
||||||
|
".rst": txtAssetParser,
|
||||||
|
".adoc": txtAssetParser,
|
||||||
|
".textile": txtAssetParser,
|
||||||
|
".opml": txtAssetParser,
|
||||||
|
".org": txtAssetParser,
|
||||||
|
".wiki": txtAssetParser,
|
||||||
".docx": &DocxAssetParser{},
|
".docx": &DocxAssetParser{},
|
||||||
".pptx": &PptxAssetParser{},
|
".pptx": &PptxAssetParser{},
|
||||||
".xlsx": &XlsxAssetParser{},
|
".xlsx": &XlsxAssetParser{},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue