Skip to content

Commit

Permalink
better brief and use local image path in ccard
Browse files Browse the repository at this point in the history
  • Loading branch information
xpgo committed Feb 14, 2021
1 parent 69559ce commit a6c6ff1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Remember to update the plugin, if you find some issues.

### 0.6.x

- use local image path in ccard (0.6.4)
- better folder note brief (0.6.4)
- folder_brief_live use plain text of md paragraph (0.6.3)
- fix the escape of quotes (0.6.2)
- folder_brief_live uses the first paragraph note for its brief (0.6.1)
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.3",
"version": "0.6.4",
"minAppVersion": "0.9.12",
"description": "Click a folder node to show a note describing the folder.",
"author": "xpgo",
Expand Down
24 changes: 15 additions & 9 deletions src/card-item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

import { App, } from "obsidian";

// ------------------------------------------------------------
// Card block
// ------------------------------------------------------------
Expand Down Expand Up @@ -29,12 +32,12 @@ export class CardBlock {
return this.cards.length;
}

getDocElement() {
getDocElement(app: App) {
const cardDiv = document.createElement('div');
if (this.style == 'card') {
cardDiv.addClass('cute-card-band');
for (var i in this.cards) {
cardDiv.appendChild(this.cards[i].getBoxElement())
cardDiv.appendChild(this.cards[i].getBoxElement(app))
}
if (this.col > 0) {
cardDiv.setAttr('style' ,
Expand All @@ -44,11 +47,6 @@ export class CardBlock {
return cardDiv;
}

getHtmlCode() {
var el = this.getDocElement();
return el.innerHTML;
}

getYamlCode() {
var yamlStr = '';
const nCard = this.getCardNum();
Expand Down Expand Up @@ -158,21 +156,29 @@ export class CardItem {
return yamlStr;
}

getBoxElement() {
getBoxElement(app: App) {
var cardEl = document.createElement('div');
cardEl.addClass('cute-card-view');
// Heading
let headEl = cardEl.appendChild(document.createElement('div'));
if (this.headImage) {
this.cardStyle = CardStyle.Image;
if (this.headImage.startsWith("#")) {
// color
headEl.addClass('thumb-color');
headEl.setAttr('style', `background-color: ${this.headImage};`);
}
else {
else if (this.headImage.contains("://")) {
// app local image
headEl.addClass('thumb');
headEl.setAttr('style', `background-image: url(${this.headImage});`);
} else {
// asset file name?
var imageUrl = app.vault.adapter.getResourcePath(this.headImage);
headEl.addClass('thumb');
headEl.setAttr('style', `background-image: url(${imageUrl});`);
}

if (this.headText) {
headEl.textContent = this.headText;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ccard-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ccardProcessor {
let cardBlock = new CardBlock();
cardBlock.fromYamlCards(yaml);
// if (yaml.style == 'card')
const cardsElem = cardBlock.getDocElement();
const cardsElem = cardBlock.getDocElement(this.app);
return cardsElem;
}
return null;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class ccardProcessor {
briefCards.col = yaml.col;
}
// if (yaml.style == 'card')
const ccardElem = briefCards.getDocElement();
const ccardElem = briefCards.getDocElement(this.app);
return ccardElem;
}
}
Expand Down
60 changes: 31 additions & 29 deletions src/folder-brief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FolderBrief {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
let briefCards = await this.makeBriefCards(folderPath, notePath);
const cardsElem = briefCards.getDocElement();
const cardsElem = briefCards.getDocElement(this.app);
return cardsElem;
}
}
Expand Down Expand Up @@ -163,31 +163,47 @@ export class FolderBrief {
}
imageUrl = headPath + '/' + imageUrl;
imageUrl = imageUrl.replace(/\%20/g, ' ')
imageUrl = this.app.vault.adapter.getResourcePath(imageUrl);
// imageUrl = this.app.vault.adapter.getResourcePath(imageUrl);
}
}
return imageUrl;
}

getContentBrief(contentOrg: string) {
var contentBrief = '';

// skip yaml head
// remove some special content
var content = contentOrg.trim();
if (content.startsWith('---')) {
const hPos2 = content.indexOf('---', 3);
if (hPos2 >= 0) {
content = contentOrg.substring(hPos2+3);
}
}
content = content
// Remove YAML code
.replace(/^---[^\(---)]*---/g, '')
// Remove HTML tags
.replace(/<[^>]*>/g, '')
// wiki style links
.replace(/\!\[\[(.*?)\]\]/g, '')
.replace(/\[\[(.*?)\]\]/g, '$1')
// Remove images
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
// Remove inline links
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
// Remove emphasis (repeat the line to remove double emphasis)
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2')
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2')
// Remove inline code
.replace(/`(.+?)`/g, '$1')
.trim()

// console.log('contentRaf', content);

// try to get the first paragraph
let regexP1 = new RegExp('\n([^\n|^#|^>|^!|^`|^\[|^-])([^\n]+)\n', 'g');
var contentBrief = '';
let regexP1 = new RegExp('\n([^\n|^#|^>])([^\n]+)\n', 'g');
var match = null;
if ((match = regexP1.exec(content)) !== null) {
contentBrief = match[1] + match[2];
}

// console.log('contentBrief', contentBrief);
contentBrief = contentBrief.trim();

// use section headings
if (contentBrief.length == 0) {
let regexHead = new RegExp('^#{1,6}(?!#)(.*)[\r\n]', 'mg');
Expand All @@ -197,25 +213,11 @@ export class FolderBrief {
break;
}
}
if (contentBrief.endsWith(', ')) {
contentBrief = contentBrief.substring(0, contentBrief.length-2);
}
}

// remove some special content
contentBrief = contentBrief
// Remove HTML tags
.replace(/<[^>]*>/g, '')
// wiki style links
.replace(/\!\[\[(.*?)\]\]/g, '')
.replace(/\[\[(.*?)\]\]/g, '$1')
// Remove images
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
// Remove inline links
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
// Remove emphasis (repeat the line to remove double emphasis)
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2')
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2')
// Remove inline code
.replace(/`(.+?)`/g, '$1')

// return
return contentBrief;
}
Expand Down
14 changes: 2 additions & 12 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
{
"0.1.0": "0.9.7",
"0.2.0": "0.9.7",
"0.2.1": "0.9.7",
"0.2.2": "0.9.7",
"0.2.3": "0.9.7",
"0.2.4": "0.9.7",
"0.2.5": "0.9.7",
"0.3.0": "0.9.7",
"0.3.1": "0.9.7",
"0.3.2": "0.9.7",
"0.3.3": "0.9.7",
"0.4.0": "0.9.7",
"0.4.1": "0.9.7",
"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.1": "0.9.7",
"0.6.2": "0.9.7",
"0.6.3": "0.9.7"
"0.6.3": "0.9.7",
"0.6.4": "0.9.7"
}

0 comments on commit a6c6ff1

Please sign in to comment.