Skip to content

Commit

Permalink
fix: update tiddlerexist usage
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Feb 24, 2025
1 parent 95fad0f commit 1ab6dae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion docs/snippets/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,6 @@ exports.sayHi = () => {
$tw.wiki.getModificationFields();

// 判断某个tiddler 是否存在
$tw.wiki.filterTiddlers(`[[your-tiddler-title]!is[missing]]`).length > 0;
$tw.wiki.tiddlerExists('title'); // 只能判断用户条目??

// $tw.wiki.filterTiddlers(`[[your-tiddler-title]!is[missing]]`).length > 0;
3 changes: 2 additions & 1 deletion plugins/oeyoews/markdown-importer/tiddlers/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ exports.startup = () => {
content.forEach((content) => {
let renameTitle = null;
if (
$tw.wiki.filterTiddlers(`[[${content.title}]!is[missing]]`).length > 0
// $tw.wiki.filterTiddlers(`[[${content.title}]!is[missing]]`).length > 0
$tw.wiki.tiddlerExists(content.title)
) {
renameTitle = window.prompt(
`${content.title} tiddler has exist, please rename this tiddler`,
Expand Down
36 changes: 26 additions & 10 deletions plugins/oeyoews/vue-random-cards/tiddlers/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,28 @@ const app = (

methods: {
randomTiddlerTitle() {
const index = (Math.random() * tiddlers.length).toFixed(0) | 0;
if (readCards.includes(tiddlers[index])) {
console.log('已经阅读过, 自动跳过该条目', tiddlers[index]);
if (tiddlers.length == 0) {
console.info('没有可用的卡片');
alert('已全部阅读');
return null;
}
const index = Math.floor(Math.random() * tiddlers.length);
console.info('pre', index, tiddlers);
const title = tiddlers.splice(index, 1)[0]; // 直接删除并获取 title
if (!$tw.wiki.tiddlerExists(title)) {
return this.randomTiddlerTitle();
} else {
readCards.push(tiddlers[index]);
return tiddlers[index];
return title;
}
},
// if (readCards.includes(tiddlers[index])) {
// console.log('已经阅读过, 自动跳过该条目', tiddlers[index]);
// tiddlers.splice(index, 1); // 移除
// return this.randomTiddlerTitle();
// } else {
// readCards.push(tiddlers[index]);
// return tiddlers[index];
// }

updateChart() {
if (this.chartdata.length > 8) {
Expand All @@ -167,7 +180,7 @@ const app = (
// this.title = '';
},

renderTiddler2HTML() {
renderTiddler2HTML(title) {
try {
// 性能问题
// const text =
Expand All @@ -177,21 +190,24 @@ const app = (
// const stateTiddler = "$:/state"
// $tw.wiki.setText(this.title, text);
this.cardContent =
$tw.wiki.renderTiddler('text/html', this.title) || '空空如也';
$tw.wiki.renderTiddler('text/html', title) || '空空如也';
} catch (e) {
console.error(e.message);
console.error(e.message, title);
}
},

updateCard: throttle(function () {
this.isRotate = !this.isRotate;
this.title = this.randomTiddlerTitle();
if (!this.title) {
return;
}
this.isRotate = !this.isRotate;
this.chartdata.push({
name: this.title,
value: 1,
});

this.renderTiddler2HTML();
this.renderTiddler2HTML(this.title);
}),

gotoTiddler() {
Expand Down

0 comments on commit 1ab6dae

Please sign in to comment.