Skip to content

Commit

Permalink
0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alangrainger committed Sep 9, 2023
1 parent e1cf654 commit 79f06a9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,12 @@ Free, encrypted public note sharing for Obsidian.

## Usage

Use the **Share Note** command from the Command Palette. You can map it to a hotkey to make things faster.
Use the `Share Note` command from the Command Palette. You can map it to a hotkey to make things faster.

The first time a file is shared, the plugin will automatically upload all your theme styles.
The next time you share the same file, it will ignore the CSS since it's already been uploaded.

**If you want to force the theme CSS to re-upload, just remove the `share_link` property from your frontmatter.**

## Advanced functions

#### Keeping the same file URL

The URL of the shared file is based on the note path + name. If you've changed the path or name and want to keep the same URL, you can add a `share_hash` YAML property with the original hash.

For example, if your URL was:

```
https://file.obsidianshare.com/572e1ae4a0aeadf5943862d1deaf8fe6.html#rhA5Um75sfBc+d1ahskptuNnriaHq3mTiEdk3Lfa4t4
```

the part you want to copy is the bit between `obsidianshare.com/` and `.html`

In this case you would set the `share_hash` property to be `572e1ae4a0aeadf5943862d1deaf8fe6` and the URL will stay the same no matter if you rename or move the Obsidian note.
If you want to force the theme CSS to update, use the command `Force re-upload of all data for this note`.

## Attributions

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "share-note",
"name": "Share Note",
"version": "0.1.4",
"version": "0.1.5",
"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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "share-note",
"version": "0.1.4",
"version": "0.1.5",
"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": {
Expand Down
16 changes: 14 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default class SharePlugin extends Plugin {
await this.loadSettings()
this.api = new API(this)

// This adds an editor command that can perform some operation on the current editor instance
// Share note
this.addCommand({
id: 'share',
id: 'share-note',
name: 'Share current note',
callback: async () => {
const note = new Note(this)
Expand All @@ -22,6 +22,18 @@ export default class SharePlugin extends Plugin {
}
})

// Share note and force a re-upload of all assets
this.addCommand({
id: 'force-upload',
name: 'Force re-upload of all data for this note',
callback: async () => {
const note = new Note(this)
note.forceUpload()
await note.parse()
note.status.hide() // clean up status just in case
}
})

this.addSettingTab(new ShareSettingsTab(this.app, this))
}

Expand Down
26 changes: 18 additions & 8 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class Note {
dom: Document
meta: CachedMetadata | null
yamlField: YamlField
isForceUpload: boolean

constructor (plugin: SharePlugin) {
this.plugin = plugin
Expand Down Expand Up @@ -121,12 +122,14 @@ export default class Note {

// Encrypt the note content

// Use previous key if it exists, so that links will stay consistent across updates
// Use previous name and key if they exist, so that links will stay consistent across updates
let shareName
let existingKey
if (this.meta?.frontmatter?.[this.yamlField.link]) {
const key = this.meta.frontmatter[this.yamlField.link].match(/#(.+)$/)
if (key) {
existingKey = key[1]
const match = this.meta.frontmatter[this.yamlField.link].match(/(\w+)\.html#(.+?)$/)
if (match) {
shareName = match[1]
existingKey = match[2]
}
}
const plaintext = JSON.stringify({
Expand All @@ -140,7 +143,9 @@ export default class Note {
}))

// Share the file
const shareName = this.meta?.frontmatter?.[this.yamlField.hash] || await hash(this.plugin.settings.uid + file.path)
if (!shareName) {
shareName = await hash(this.plugin.settings.uid + Date.now())
}
const shareFile = shareName + '.html'

const baseRes = await this.upload({
Expand Down Expand Up @@ -196,11 +201,12 @@ export default class Note {
}

/**
* Upload theme CSS, unless this file has previously been shared.
* To force a CSS re-upload, just remove the `share_link` frontmatter field.
* Upload theme CSS, unless this file has previously been shared,
* or the user has requested a force re-upload
*/
async uploadCss () {
if (!this.meta?.frontmatter?.[this.yamlField.link]) {
if (!this.meta?.frontmatter?.[this.yamlField.link] || this.isForceUpload) {
console.log('css')
await this.upload({ filename: this.plugin.settings.uid + '.css', content: this.css })
// Extract any base64 encoded attachments from the CSS.
// Will use the mime-type whitelist to determine which attachments to extract.
Expand Down Expand Up @@ -238,4 +244,8 @@ export default class Note {
}
return Object.keys(mimes).find(x => mimes[x].includes((mimeType || '').toLowerCase()))
}

forceUpload () {
this.isForceUpload = true
}
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.1.3": "0.15.0",
"0.1.4": "0.15.0"
"0.1.4": "0.15.0",
"0.1.5": "0.15.0"
}

0 comments on commit 79f06a9

Please sign in to comment.