forked from oleeskild/obsidian-digital-garden
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from saberzero1/v2
- Loading branch information
Showing
14 changed files
with
272 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
# Obsidian Quartz Syncer | ||
|
||
Parse, upload and sync your Obsidian notes to your [Quartz](https://github.com/jackyzha0/quartz) website. | ||
|
||
**This plugin assumes you have set up a Quartz repository.** | ||
|
||
## Initial Setup | ||
|
||
Install the plugin by downloading it from the <a href="https://github.com/saberzero1/quartz-syncer/releases">Release Tab</a>, or through the <a href="https://github.com/TfTHacker/obsidian42-brat">Obsidian42 Brat plugin</a>. | ||
|
||
After installing, open the plugin settings in Obsidian and set your Github Username, the name of your fork of [Quartz](https://github.com/jackyzha0/quartz), and the authentication token. | ||
|
||
Don't have an authentication token yet? You can generate it <a href="https://github.com/settings/tokens/new?scopes=repo">here</a>. | ||
|
||
## Publishing notes to Quartz | ||
|
||
You can click on the icon in the sidebar or launch the `Quartz Syncer: Open Publication Center` to publish/unpublish notes. | ||
|
||
> [!IMPORTANT] | ||
> Notes need a `publish` flag in the notes <a href="https://help.obsidian.md/Editing+and+formatting/Properties">frontmatter</a>. You can add these with the `Quartz Syncer: Add Publish Flag` command, or by adding them to the notes properties manually or via template. | ||
The following frontmatter in a note will cause it to be published when opening the Publication Center: | ||
|
||
```yaml | ||
publish: true | ||
``` | ||
The following frontmatter in a note will cause it to be shown in the Publication Center, but not published. | ||
```yaml | ||
publish: false | ||
``` | ||
The notes will appear in the `content` folder in your chosen repository. | ||
|
||
## Credits | ||
|
||
This repository is a modified version of <a href="https://github.com/oleeskild">Ole's</a> <a href="https://github.com/oleeskild/obsidian-digital-garden">Digital Garden plugin</a>. If you found this project useful and want to support it, please support him instead: <a href="https://ko-fi.com/oleeskild">Donation link</a>. | ||
# Obsidian Quartz Syncer | ||
|
||
Parse, upload and sync your Obsidian notes to your [Quartz](https://github.com/jackyzha0/quartz) website. | ||
|
||
**This plugin assumes you have set up a Quartz repository.** | ||
|
||
## Initial Setup | ||
|
||
Install the plugin by downloading it from the <a href="https://github.com/saberzero1/quartz-syncer/releases">Release Tab</a>, or through the <a href="https://github.com/TfTHacker/obsidian42-brat">Obsidian42 Brat plugin</a>. | ||
|
||
After installing, open the plugin settings in Obsidian and set your Github Username, the name of your fork of [Quartz](https://github.com/jackyzha0/quartz), and the authentication token. | ||
|
||
Don't have an authentication token yet? You can generate it <a href="https://github.com/settings/tokens/new?scopes=repo">here</a>. | ||
|
||
## Publishing notes to Quartz | ||
|
||
You can click on the icon in the sidebar or launch the `Quartz Syncer: Open Publication Center` to publish/unpublish notes. | ||
|
||
> [!IMPORTANT] | ||
> Notes need a `publish` flag in the notes <a href="https://help.obsidian.md/Editing+and+formatting/Properties">frontmatter</a>. You can add these with the `Quartz Syncer: Add Publish Flag` command, or by adding them to the notes properties manually or via template. | ||
The following frontmatter in a note will cause it to be published when opening the Publication Center: | ||
|
||
```yaml | ||
publish: true | ||
``` | ||
The following frontmatter in a note will cause it to be shown in the Publication Center, but not published. | ||
```yaml | ||
publish: false | ||
``` | ||
The notes will appear in the `content` folder in your chosen repository. | ||
|
||
## Credits | ||
|
||
This repository is a modified version of <a href="https://github.com/oleeskild">Ole's</a> <a href="https://github.com/oleeskild/obsidian-digital-garden">Digital Garden plugin</a>. If you found this project useful and want to support it, please support him instead: <a href="https://ko-fi.com/oleeskild">Donation link</a>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
dg-publish: true | ||
--- | ||
These codeblocks should not be modified upon publish. | ||
|
||
Sample 1 | ||
```jinja2 | ||
{{ highlight_text }}{% if highlight_location and highlight_location_url %} ([via]({{highlight_location_url}})){% elif highlight_location %} ({{highlight_location}}){% endif %} ^rwhi{{highlight_id}} | ||
{% if highlight_note %} | ||
{{ highlight_note }} ^rwhi{{highlight_id}}-note | ||
{% endif %} | ||
``` | ||
|
||
Sample 2 | ||
```md | ||
In medieval Latin a florilegium (plural florilegia) was a compilation of excerpts from other writings. | ||
The word is from the Latin flos (flower) and legere (to gather): literally a gathering of flowers, or collection of fine extracts from the body of a larger work. ([via](https://en.wikipedia.org/wiki/Florilegium)) ^rwhi724352030 | ||
``` | ||
|
||
Sample 3 | ||
``` | ||
This codeblock has a transclusion syntax in it. | ||
Check it out: ![[001 Links]] | ||
``` | ||
|
||
And for sanity, here's some block references outside of code blocks: foobar ^test-123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { replaceBlockIDs } from "./replaceBlockIDs"; | ||
|
||
describe("replaceBlockIDs", () => { | ||
it("should replace block IDs in markdown", () => { | ||
const EXPECTED_MARKDOWN = ` | ||
# header | ||
foo ^block-id-1234 | ||
bar ^block-id-5678 | ||
`; | ||
|
||
const result = replaceBlockIDs(EXPECTED_MARKDOWN); | ||
|
||
expect(result).toBe(` | ||
# header | ||
foo | ||
{ #block-id-1234} | ||
bar | ||
{ #block-id-5678} | ||
`); | ||
}); | ||
|
||
it("should not replace block IDs in code blocks", () => { | ||
const CODEBLOCK_WITH_BLOCKIDS = ` | ||
\`\`\` | ||
foobar. | ||
this is a code block. | ||
but it contains a block ID to try to fool the compiler | ||
and, consequently, wreck your garden. | ||
here it goes: ^block-id-1234 | ||
and for fun, here's another: ^block-id-5678 | ||
\`\`\` | ||
additionally, block IDs outside of code blocks should be replaced | ||
for example, ^block-id-9999 | ||
and ^block-id-0000 | ||
`; | ||
|
||
const result = replaceBlockIDs(CODEBLOCK_WITH_BLOCKIDS); | ||
|
||
expect(result).toBe(` | ||
\`\`\` | ||
foobar. | ||
this is a code block. | ||
but it contains a block ID to try to fool the compiler | ||
and, consequently, wreck your garden. | ||
here it goes: ^block-id-1234 | ||
and for fun, here's another: ^block-id-5678 | ||
\`\`\` | ||
additionally, block IDs outside of code blocks should be replaced | ||
for example, | ||
{ #block-id-9999} | ||
and | ||
{ #block-id-0000} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function replaceBlockIDs(markdown: string) { | ||
const block_pattern = / \^([\w\d-]+)/g; | ||
const complex_block_pattern = /\n\^([\w\d-]+)\n/g; | ||
|
||
// To ensure code blocks are not modified... | ||
const codeBlockPattern = /```[\s\S]*?```/g; | ||
|
||
// Extract code blocks and replace them with placeholders | ||
const codeBlocks: string[] = []; | ||
|
||
markdown = markdown.replace(codeBlockPattern, (match) => { | ||
codeBlocks.push(match); | ||
|
||
return `{{CODE_BLOCK_${codeBlocks.length - 1}}}`; | ||
}); | ||
|
||
// Replace patterns outside code blocks | ||
markdown = markdown.replace( | ||
complex_block_pattern, | ||
(_match: string, $1: string) => { | ||
return `{ #${$1}}\n\n`; | ||
}, | ||
); | ||
|
||
markdown = markdown.replace(block_pattern, (_match: string, $1: string) => { | ||
return `\n{ #${$1}}\n`; | ||
}); | ||
|
||
// Reinsert code blocks | ||
codeBlocks.forEach((block, index) => { | ||
markdown = markdown.replace(`{{CODE_BLOCK_${index}}}`, block); | ||
}); | ||
|
||
return markdown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.