Set theme mode on upload
This commit is contained in:
Alan Grainger 2023-09-20 13:03:04 +02:00
parent 3f322fbf96
commit a70e70bea4
8 changed files with 75 additions and 22 deletions

View file

@ -1,7 +1,7 @@
{
"id": "share-note",
"name": "Share Note",
"version": "0.2.13",
"version": "0.3.0",
"minAppVersion": "0.15.0",
"description": "Share a note publicly with full styling. Data is stored encrypted on the server and only you have the key.",
"author": "Alan Grainger",

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "share-note",
"version": "0.2.5",
"version": "0.3.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "share-note",
"version": "0.2.5",
"version": "0.3.0",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",

View file

@ -1,6 +1,6 @@
{
"name": "share-note",
"version": "0.2.13",
"version": "0.3.0",
"description": "Share a note publicly with full styling. Data is stored encrypted on the server and only you have the key.",
"main": "main.js",
"scripts": {

View file

@ -12,8 +12,8 @@ const statusCodes: { [key: number]: string } = {
}
export interface UploadData {
filename: string;
content: string;
filename?: string;
content?: string;
encoding?: string;
}
@ -24,7 +24,7 @@ export default class API {
this.plugin = plugin
}
async post (endpoint: string, data: any = {}) {
async post (endpoint: string, data: UploadData = {}) {
Object.assign(data, {
id: this.plugin.settings.uid,
key: this.plugin.settings.apiKey,

View file

@ -96,6 +96,7 @@ export default class Note {
if (!this.plugin.settings.showFooter) {
this.outputFile.removeFooter()
}
this.outputFile.setThemeMode(this.plugin.settings.themeMode) // must be after setBodyClasses
// Generate the HTML file for uploading
this.dom = new DOMParser().parseFromString(this.content, 'text/html')

View file

@ -1,12 +1,19 @@
import { App, PluginSettingTab, Setting, TextComponent } from 'obsidian'
import SharePlugin from './main'
export enum ThemeMode {
'Same as theme',
Dark,
Light
}
export interface ShareSettings {
server: string;
uid: string;
apiKey: string;
yamlField: string;
noteWidth: string;
themeMode: ThemeMode;
showFooter: boolean;
removeYaml: boolean;
clipboard: boolean;
@ -18,6 +25,7 @@ export const DEFAULT_SETTINGS: ShareSettings = {
apiKey: '',
yamlField: 'share',
noteWidth: '700px',
themeMode: ThemeMode['Same as theme'],
showFooter: true,
removeYaml: true,
clipboard: true
@ -37,6 +45,10 @@ export class ShareSettingsTab extends PluginSettingTab {
containerEl.empty()
new Setting(containerEl)
.setName('Plugin setup')
.setHeading()
// API key
new Setting(containerEl)
.setName('API key')
@ -70,6 +82,26 @@ export class ShareSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings()
}))
new Setting(containerEl)
.setName('Upload options')
.setHeading()
// Show/hide the footer
new Setting(containerEl)
.setName('Light/Dark mode')
.setDesc('Choose the mode with which your files will be shared')
.addDropdown(dropdown => {
dropdown
.addOption('Same as theme', 'Same as theme')
.addOption('Dark', 'Dark')
.addOption('Light', 'Light')
.setValue(ThemeMode[this.plugin.settings.themeMode])
.onChange(async value => {
this.plugin.settings.themeMode = ThemeMode[value as keyof typeof ThemeMode]
await this.plugin.saveSettings()
})
})
// Strip frontmatter
new Setting(containerEl)
.setName('Remove published frontmatter/YAML')
@ -84,19 +116,6 @@ export class ShareSettingsTab extends PluginSettingTab {
})
})
// Show/hide the footer
new Setting(containerEl)
.setName('Show the footer')
.addToggle(toggle => {
toggle
.setValue(this.plugin.settings.showFooter)
.onChange(async (value) => {
this.plugin.settings.showFooter = value
await this.plugin.saveSettings()
this.display()
})
})
// Copy to clipboard
new Setting(containerEl)
.setName('Copy the link to clipboard after sharing')
@ -110,6 +129,23 @@ export class ShareSettingsTab extends PluginSettingTab {
})
})
// Show/hide the footer
new Setting(containerEl)
.setName('Show the footer')
.addToggle(toggle => {
toggle
.setValue(this.plugin.settings.showFooter)
.onChange(async (value) => {
this.plugin.settings.showFooter = value
await this.plugin.saveSettings()
this.display()
})
})
new Setting(containerEl)
.setName('Debug info')
.setHeading()
new Setting(containerEl)
.setName('User ID')
.setDesc('If you need it for debugging purposes, this is your user ID')

View file

@ -1,6 +1,10 @@
// noinspection CssInvalidPropertyValue,HtmlRequiredLangAttribute,HtmlUnknownTarget
import { ThemeMode } from './settings'
/**
* CSS info:
*
* .reading-view-extra gives a custom width for the note text.
* .status-bar makes the status bar pinned to the right, rather than full-page.
*/
@ -67,7 +71,7 @@ const html = `
document.body.classList.remove(...mobileClasses)
}
}
window.addEventListener('resize', toggleMobileClasses })
window.addEventListener('resize', toggleMobileClasses )
toggleMobileClasses()
function base64ToArrayBuffer(base64) {
@ -195,4 +199,15 @@ export default class Template {
this.dom.head.appendChild(desc)
this.dom.head.appendChild(ogDesc)
}
setThemeMode (mode: ThemeMode) {
if (mode === ThemeMode['Same as theme']) {
// Nothing to change
} else {
// Remove the existing theme
this.dom.body.removeClasses(['theme-dark', 'theme-light'])
// Add the preferred class
this.dom.body.addClasses(['theme-' + ThemeMode[mode]])
}
}
}

View file

@ -19,5 +19,6 @@
"0.2.10": "0.15.0",
"0.2.11": "0.15.0",
"0.2.12": "0.15.0",
"0.2.13": "0.15.0"
"0.2.13": "0.15.0",
"0.3.0": "0.15.0"
}