Skip to content

Commit

Permalink
Merge pull request #3 from lucaorio/plugin-review
Browse files Browse the repository at this point in the history
Plugin review #2
  • Loading branch information
lucaorio authored Jun 1, 2022
2 parents 1cdba09 + 692340d commit bf328d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
15 changes: 0 additions & 15 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@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
23 changes: 11 additions & 12 deletions src/img-gallery-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { App, MarkdownRenderChild, TFolder, TFile, Platform, normalizePath } from 'obsidian'
import * as jsyaml from 'js-yaml'
import { App, MarkdownRenderChild, TFolder, TFile, Platform, normalizePath, parseYaml } from 'obsidian'
import ImgGallery from './main'

export class imgGalleryRenderer extends MarkdownRenderChild {
private _gallery: HTMLElement = null
private _settings: {[key: string]: any} = {}
private _imagesList: string[] = null
private _imagesList: string[] = []

constructor(
public plugin: ImgGallery,
Expand Down Expand Up @@ -34,7 +33,7 @@ export class imgGalleryRenderer extends MarkdownRenderChild {

private _getSettings() {
// parse the settings from the code block
const settingsObj: any = jsyaml.load(this.src)
const settingsObj: any = parseYaml(this.src)

// check for required settings
if (settingsObj === undefined) {
Expand All @@ -52,19 +51,19 @@ export class imgGalleryRenderer extends MarkdownRenderChild {
// store settings, normalize and set sensible defaults
this._settings.path = normalizePath(settingsObj.path)

this._settings.type = settingsObj.type || 'horizontal'
this._settings.radius = settingsObj.radius || '0'
this._settings.gutter = settingsObj.gutter || '8'
this._settings.sortby = settingsObj.sortby || 'ctime'
this._settings.sort = settingsObj.sort || 'desc'
this._settings.type = settingsObj.type ?? 'horizontal'
this._settings.radius = settingsObj.radius ?? 0
this._settings.gutter = settingsObj.gutter ?? 8
this._settings.sortby = settingsObj.sortby ?? 'ctime'
this._settings.sort = settingsObj.sort ?? 'desc'

// settings for vertical mansory only
this._settings.mobile = settingsObj.mobile || '1'
if (Platform.isDesktop) this._settings.columns = settingsObj.columns || '3'
this._settings.mobile = settingsObj.mobile ?? 1
if (Platform.isDesktop) this._settings.columns = settingsObj.columns ?? 3
else this._settings.columns = this._settings.mobile

// settings for horizontal mansory only
this._settings.height = settingsObj.height || '260'
this._settings.height = settingsObj.height ?? 260
}

private _getImagesList() {
Expand Down

0 comments on commit bf328d9

Please sign in to comment.