Skip to content

Commit

Permalink
wiki like image
Browse files Browse the repository at this point in the history
  • Loading branch information
xpgo committed Feb 13, 2021
1 parent 4834507 commit c51e02f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ The keyword {{FOLDER_BRIEF_LIVE}} will be replaced with a `ccard` code block wh

Remember to update the plugin, if you find some issues.

### 0.6.1

- folder_brief_live uses the first paragraph note for its brief
- folder_brief_live supports wiki style image

### 0.6.0

- Add option for the key to create new note (0.6.0)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "folder-note-plugin",
"name": "Folder Note",
"version": "0.6.0",
"version": "0.6.1",
"minAppVersion": "0.9.12",
"description": "Click a folder node to show a note describing the folder.",
"author": "xpgo",
Expand Down
31 changes: 25 additions & 6 deletions src/folder-brief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,21 @@ export class FolderBrief {
let content = await this.app.vault.cachedRead(file);
// let content = await this.app.vault.adapter.read(notePath);
// console.log(content);
var imageUrl = '';
// for patten: ![xxx.png]
let regexImg = new RegExp('!\\[(.*?)\\]\\((.*?)\\)');
var match = regexImg.exec(content);
if (match != null) {
var imageUrl = match[2];
imageUrl = match[2];
}
else {
// for patten: ![[xxx.png]]
let regexImg2 = new RegExp('!\\[\\[(.*?)\\]\\]');
match = regexImg2.exec(content);
if (match != null) imageUrl = match[1];
}
// add image url
if (imageUrl.length > 0) {
if (!imageUrl.startsWith('http')) {
var headPath = folderPath;
while (imageUrl.startsWith('../')) {
Expand All @@ -120,11 +131,19 @@ export class FolderBrief {
}
// content?
var contentBrief = '';
let regexHead = new RegExp('^#{1,6}(?!#)(.*)[\r\n]', 'mg');
while ((match = regexHead.exec(content)) !== null) {
contentBrief += match[1] + ', ';
if (contentBrief.length > 32) {
break;
// first paragraph
let regexP1 = new RegExp('\n([^\n|^#|^>|^!|^`|^\[|^-])([^\n]+)\n', 'g');
if ((match = regexP1.exec(content)) !== null) {
contentBrief = match[1] + match[2];
}
// use section headings
if (contentBrief.length == 0) {
let regexHead = new RegExp('^#{1,6}(?!#)(.*)[\r\n]', 'mg');
while ((match = regexHead.exec(content)) !== null) {
contentBrief += match[1] + ', ';
if (contentBrief.length > 32) {
break;
}
}
}
if (contentBrief.length > 0) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"0.5.0": "0.9.7",
"0.5.1": "0.9.7",
"0.5.2": "0.9.7",
"0.6.0": "0.9.7"
"0.6.0": "0.9.7",
"0.6.1": "0.9.7"
}

0 comments on commit c51e02f

Please sign in to comment.