Skip to content

Commit

Permalink
introduced yaml formatting, improved error check
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaorio committed May 20, 2022
1 parent 1b10692 commit 71ae9d2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
],
"license": "MIT",
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"js-yaml": "^4.1.0",
"obsidian": "latest",
"tslib": "2.3.1",
"typescript": "^4.4.4"
Expand Down
26 changes: 14 additions & 12 deletions src/img-gallery-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, MarkdownRenderChild, TFolder, TFile, Platform, normalizePath } from 'obsidian'
import * as jsyaml from 'js-yaml'
import ImgGallery from './main'

export class imgGalleryRenderer extends MarkdownRenderChild {
Expand All @@ -25,26 +26,27 @@ export class imgGalleryRenderer extends MarkdownRenderChild {
}

async onunload() {
this._gallery.remove()
this._gallery = null
if (this._gallery) {
this._gallery.remove()
this._gallery = null
}
}

private _getSettings() {
// parse the settings from the code block
const settingsObj: {[key: string]: string} = {}

this.src.split('\n')
.filter((row) => row.length > 0)
.forEach((item) => {
const setting = item.split('=')
settingsObj[setting[0]] = setting[1]
})
const settingsObj: any = jsyaml.load(this.src)

// check for required settings
if (settingsObj === undefined) {
const error = 'Cannot parse YAML!'
this._renderError(error)
throw new Error(error)
}

if (!settingsObj.path) {
const error = 'Please specify a path!'
this._renderError(error)
throw new Error(error);
throw new Error(error)
}

// store settings, normalize and set sensible defaults
Expand Down Expand Up @@ -74,7 +76,7 @@ export class imgGalleryRenderer extends MarkdownRenderChild {
else {
const error = 'The folder doesn\'t exist, or it\'s empty!'
this._renderError(error)
throw new Error(error);
throw new Error(error)
}

// filter the list of files to make sure we're dealing with images only
Expand Down

0 comments on commit 71ae9d2

Please sign in to comment.