Merge branch 'ivan-lednev-default-tag' into main

This commit is contained in:
Alex Colucci 2021-06-23 20:35:22 +02:00
commit c5bb409d94
8 changed files with 57 additions and 4 deletions

13
.github/workflows/greetings.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Greetings
on: [pull_request, issues]
jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thank you for taking the time to report the issue and help me to make the project better! 🙂'
pr-message: 'Thank you for helping me to make the project better! 🙂'

22
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Mark stale issues and pull requests
on:
schedule:
- cron: "0 13 * * *"
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
any-of-labels: 'awaiting feedback'
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-label: 'stale'
stale-pr-label: 'stale'
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
stale-pr-message: 'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
close-issue-message: 'This issue was closed because it has been stalled for 7 days with no activity.'
close-pr-message: 'This PR was closed because it has been stalled for 7 days with no activity.'

View File

@ -56,7 +56,7 @@ export default class ObsidianFlashcard extends Plugin {
}
private getDefaultSettings(): ISettings {
return { contextAwareMode: true, sourceSupport: false, codeHighlightSupport: false, contextSeparator: " > ", deck: "Default", flashcardsTag: "card" }
return { contextAwareMode: true, sourceSupport: false, codeHighlightSupport: false, contextSeparator: " > ", deck: "Default", flashcardsTag: "card", defaultAnkiTag: "obsidian" }
}
private generateCards(activeFile: TFile) {

View File

@ -16,7 +16,6 @@ export abstract class Card {
containsCode: boolean
modelName: string
// TODO set "obsidian as optional in the settings", this means that the tag should be outside
constructor(id: number, deckName: string, initialContent: string, fields: Record<string, string>, reversed: boolean, endOffset: number, tags: string[], inserted: boolean, mediaNames: string[], containsCode: boolean = false) {
this.id = id
this.deckName = deckName
@ -25,7 +24,6 @@ export abstract class Card {
this.reversed = reversed
this.endOffset = endOffset
this.tags = tags
this.tags.unshift("obsidian")
this.inserted = inserted
this.mediaNames = mediaNames
this.mediaBase64Encoded = []

View File

@ -3,7 +3,8 @@ import { Card } from "src/entities/card";
export class Inlinecard extends Card {
constructor(id: number = -1, deckName: string, initialContent: string, fields: Record<string, string>, reversed: boolean, endOffset: number, tags: string[] = [], inserted: boolean = false, mediaNames: string[], containsCode: boolean) {
super(id, deckName, initialContent, fields, reversed, endOffset, tags, inserted, mediaNames, [], containsCode) // ! CHANGE []
super(id, deckName, initialContent, fields, reversed, endOffset, tags, inserted, mediaNames, containsCode) // ! CHANGE []
this.modelName = this.reversed ? `Obsidian-basic-reversed` : `Obsidian-basic`
if (fields["Source"]) {
this.modelName += sourceDeckExtension

View File

@ -88,6 +88,18 @@ export class SettingsTab extends PluginSettingTab {
})
})
new Setting(containerEl)
.setName("Default Anki tag")
.setDesc("This tag will be added to each generated card on Anki")
.addText((text) => {
text.setValue(plugin.settings.defaultAnkiTag)
.setPlaceholder("Anki tag")
.onChange((value) => {
if (!value) new Notice("No default tags will be added")
plugin.settings.defaultAnkiTag = value.toLowerCase()
plugin.saveData(plugin.settings)
})
})
}
}

View File

@ -148,6 +148,12 @@ export class CardsService {
if (cardsToCreate.length) {
let insertedCards = 0
try {
let defaultAnkiTag = this.settings.defaultAnkiTag
if (defaultAnkiTag) {
for (const card of cardsToCreate) {
card.tags.push(defaultAnkiTag)
}
}
let ids = await this.anki.addCards(cardsToCreate)
// Add IDs from response to Flashcard[]
ids.map((id: number, index: number) => {

View File

@ -5,4 +5,5 @@ export interface ISettings {
contextSeparator: string
deck: string
flashcardsTag: string
defaultAnkiTag: string
}