Skip to content

Commit 38fb956

Browse files
committed
Fix broken link titles when illegal characters present
1 parent 771485f commit 38fb956

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.0.2 (2021-05-24)
4+
### Fixed
5+
- Fixed linking bug when illegal characters were stripped in filename, but not in Note title (https://github.com/jsonMartin/readwise-mirror/issues/4)
6+
### Changed
7+
- Starting default sort order preference now sorts highlights chronologically from oldest to newest
8+
39
## 1.0.1 (2021-05-24)
410
### Added
511
- Added new checkbox in settings to allow highlights to be listed in reverse chronological order

main.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const DEFAULT_SETTINGS: PluginSettings = {
1717
apiToken: null,
1818
lastUpdated: null,
1919
autoSync: true,
20-
highlightSortOldestToNewest: false,
20+
highlightSortOldestToNewest: true,
2121
};
2222

2323
export default class ReadwiseMirror extends Plugin {
@@ -75,7 +75,7 @@ ${text} ${book.category === 'books' ? locationBlock : ''}${color ? ` %% Color: $
7575
last_highlight_at,
7676
source_url,
7777
} = book;
78-
const fileName = `${title.replace(/[<>:"\/\\|?*]+/g, '')}.md`;
78+
const sanitizedTitle = `${title.replace(':', '-').replace(/[<>"'\/\\|?*]+/g, '')}`;
7979

8080
const formattedHighlights = (this.settings.highlightSortOldestToNewest ? highlights.reverse() : highlights)
8181
.map((highlight: Highlight) => this.formatHighlight(highlight, book))
@@ -101,15 +101,18 @@ Updated: ${this.formatDate(updated)}
101101
![](${cover_image_url.replace('SL200', 'SL500').replace('SY160', 'SY500')})
102102
103103
# About
104-
Title: [[${title}]]
104+
Title: [[${sanitizedTitle}]]
105105
${authors.length > 1 ? 'Authors' : 'Author'}: ${authorStr}
106106
Category: #${category}
107107
Number of Highlights: ==${num_highlights}==
108108
Last Highlighted: *${last_highlight_at ? this.formatDate(last_highlight_at) : 'Never'}*
109109
Readwise URL: ${highlights_url}${category === 'articles' ? `\nSource URL: ${source_url}\n` : ''}
110110
111111
# Highlights ${formattedHighlights}`;
112-
let path = `${this.settings.baseFolderName}/${category.charAt(0).toUpperCase() + category.slice(1)}/${fileName}`;
112+
113+
let path = `${this.settings.baseFolderName}/${
114+
category.charAt(0).toUpperCase() + category.slice(1)
115+
}/${sanitizedTitle}.md`;
113116

114117
const abstractFile = vault.getAbstractFileByPath(path);
115118

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "readwise-mirror",
33
"name": "Readwise Mirror",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"minAppVersion": "0.11.0",
66
"description": "Mirror your Readwise library directly to an Obsidian vault",
77
"author": "jsonmartin",

0 commit comments

Comments
 (0)