mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
🎨 Support searching some plaintext assets content https://github.com/siyuan-note/siyuan/issues/8987
This commit is contained in:
parent
e87b831da7
commit
620853575b
2 changed files with 42 additions and 41 deletions
|
|
@ -357,47 +357,35 @@ export const assetMethodMenu = (target: HTMLElement, cb: () => void) => {
|
||||||
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let filterTypes: string[] = [
|
||||||
|
".txt", ".md", ".markdown", ".docx", ".xlsx", ".pptx", ".json", ".log", ".sql", ".html", ".xml", ".java", ".h", ".c",
|
||||||
|
".cpp", ".go", ".rs", ".swift", ".kt", ".py", ".php", ".js", ".css", ".ts", ".sh", ".bat", ".cmd", ".ini", ".yaml",
|
||||||
|
".rst", ".adoc", ".textile", ".opml", ".org", ".wiki",
|
||||||
|
]
|
||||||
|
|
||||||
|
const filterTypesHTML = (types: string[]) => {
|
||||||
|
filterTypes = filterTypes.sort((a: string, b: string) => {
|
||||||
|
return a.localeCompare(b);
|
||||||
|
});
|
||||||
|
|
||||||
|
let html = "";
|
||||||
|
types.forEach((type: string) => {
|
||||||
|
html += `<label class="fn__flex b3-label">
|
||||||
|
<div class="fn__flex-1 fn__flex-center">
|
||||||
|
${type}
|
||||||
|
</div>
|
||||||
|
<span class="fn__space"></span>
|
||||||
|
<input class="b3-switch fn__flex-center" data-type="${type}" type="checkbox" checked>
|
||||||
|
</label>`;
|
||||||
|
});
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
export const assetFilterMenu = (assetsElement: Element) => {
|
export const assetFilterMenu = (assetsElement: Element) => {
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHASSET].types;
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHASSET].types;
|
||||||
const filterDialog = new Dialog({
|
const filterDialog = new Dialog({
|
||||||
title: window.siyuan.languages.type,
|
title: window.siyuan.languages.type,
|
||||||
content: `<div class="b3-dialog__content">
|
content: `<div class="b3-dialog__content">` + filterTypesHTML(filterTypes) + `</div>
|
||||||
<label class="fn__flex b3-label">
|
|
||||||
<div class="fn__flex-1 fn__flex-center">
|
|
||||||
.txt
|
|
||||||
</div>
|
|
||||||
<span class="fn__space"></span>
|
|
||||||
<input class="b3-switch fn__flex-center" data-type=".txt" type="checkbox"${localData[".txt"] ? " checked" : ""}>
|
|
||||||
</label>
|
|
||||||
<label class="fn__flex b3-label">
|
|
||||||
<div class="fn__flex-1 fn__flex-center">
|
|
||||||
.md
|
|
||||||
</div>
|
|
||||||
<span class="fn__space"></span>
|
|
||||||
<input class="b3-switch fn__flex-center" data-type=".md" type="checkbox"${localData[".md"] ? " checked" : ""}>
|
|
||||||
</label>
|
|
||||||
<label class="fn__flex b3-label">
|
|
||||||
<div class="fn__flex-1 fn__flex-center">
|
|
||||||
.docx
|
|
||||||
</div>
|
|
||||||
<span class="fn__space"></span>
|
|
||||||
<input class="b3-switch fn__flex-center" data-type=".docx" type="checkbox"${localData[".docx"] ? " checked" : ""}>
|
|
||||||
</label>
|
|
||||||
<label class="fn__flex b3-label">
|
|
||||||
<div class="fn__flex-1 fn__flex-center">
|
|
||||||
.xlsx
|
|
||||||
</div>
|
|
||||||
<span class="fn__space"></span>
|
|
||||||
<input class="b3-switch fn__flex-center" data-type=".xlsx" type="checkbox"${localData[".xlsx"] ? " checked" : ""}>
|
|
||||||
</label>
|
|
||||||
<label class="fn__flex b3-label">
|
|
||||||
<div class="fn__flex-1 fn__flex-center">
|
|
||||||
.pptx
|
|
||||||
</div>
|
|
||||||
<span class="fn__space"></span>
|
|
||||||
<input class="b3-switch fn__flex-center" data-type=".pptx" type="checkbox"${localData[".pptx"] ? " checked" : ""}>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="b3-dialog__action">
|
<div class="b3-dialog__action">
|
||||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||||
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ func IndexAssetContent(absPath string) {
|
||||||
|
|
||||||
assetsDir := util.GetDataAssetsAbsPath()
|
assetsDir := util.GetDataAssetsAbsPath()
|
||||||
|
|
||||||
ext := strings.ToLower(filepath.Ext(absPath))
|
ext := filepath.Ext(absPath)
|
||||||
parser := assetContentSearcher.GetParser(ext)
|
parser := assetContentSearcher.GetParser(ext)
|
||||||
if nil == parser {
|
if nil == parser {
|
||||||
return
|
return
|
||||||
|
|
@ -360,7 +360,7 @@ func (searcher *AssetsSearcher) GetParser(ext string) AssetParser {
|
||||||
searcher.lock.Lock()
|
searcher.lock.Lock()
|
||||||
defer searcher.lock.Unlock()
|
defer searcher.lock.Unlock()
|
||||||
|
|
||||||
return searcher.parsers[ext]
|
return searcher.parsers[strings.ToLower(ext)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (searcher *AssetsSearcher) FullIndex() {
|
func (searcher *AssetsSearcher) FullIndex() {
|
||||||
|
|
@ -382,7 +382,7 @@ func (searcher *AssetsSearcher) FullIndex() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := strings.ToLower(filepath.Ext(absPath))
|
ext := filepath.Ext(absPath)
|
||||||
parser := searcher.GetParser(ext)
|
parser := searcher.GetParser(ext)
|
||||||
if nil == parser {
|
if nil == parser {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -433,9 +433,11 @@ func NewAssetsSearcher() *AssetsSearcher {
|
||||||
".c": txtAssetParser,
|
".c": txtAssetParser,
|
||||||
".cpp": txtAssetParser,
|
".cpp": txtAssetParser,
|
||||||
".go": txtAssetParser,
|
".go": txtAssetParser,
|
||||||
|
".rs": txtAssetParser,
|
||||||
".swift": txtAssetParser,
|
".swift": txtAssetParser,
|
||||||
".kt": txtAssetParser,
|
".kt": txtAssetParser,
|
||||||
".py": txtAssetParser,
|
".py": txtAssetParser,
|
||||||
|
".php": txtAssetParser,
|
||||||
".js": txtAssetParser,
|
".js": txtAssetParser,
|
||||||
".css": txtAssetParser,
|
".css": txtAssetParser,
|
||||||
".ts": txtAssetParser,
|
".ts": txtAssetParser,
|
||||||
|
|
@ -460,6 +462,10 @@ func NewAssetsSearcher() *AssetsSearcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
TxtAssetContentMaxSize = 1024 * 1024 * 4
|
||||||
|
)
|
||||||
|
|
||||||
type AssetParseResult struct {
|
type AssetParseResult struct {
|
||||||
Path string
|
Path string
|
||||||
Size int64
|
Size int64
|
||||||
|
|
@ -475,7 +481,14 @@ type TxtAssetParser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (parser *TxtAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
func (parser *TxtAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
||||||
if !strings.HasSuffix(strings.ToLower(absPath), ".txt") {
|
info, err := os.Stat(absPath)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("stat file [%s] failed: %s", absPath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if TxtAssetContentMaxSize < info.Size() {
|
||||||
|
logging.LogWarnf("file [%s] is too large [%s]", absPath, humanize.Bytes(uint64(info.Size())))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue