Skip to content

Commit

Permalink
Merge pull request #12 from decaf-dev/dev
Browse files Browse the repository at this point in the history
1.1.1
  • Loading branch information
decaf-dev authored Aug 11, 2024
2 parents ec6bb0d + f2e2050 commit 85e111c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Obsidian Downloads](https://img.shields.io/badge/dynamic/json?logo=obsidian&color=%23483699&label=downloads&query=%24%5B%22note-splitter%22%5D.downloads&url=https%3A%2F%2Fraw.githubusercontent.com%2Fobsidianmd%2Fobsidian-releases%2Fmaster%2Fcommunity-plugin-stats.json)

Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only. It allows you to split a single Obsidian note into many notes based on a specified sequence of characters (a delimiter). The default delimiter is a new line.
Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only. It allows you to split a single note into many notes based on a specified sequence of characters (a delimiter).

## Table of contents

Expand All @@ -15,13 +15,13 @@ Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only.

## Videos

Splitting a note without changing any settings
Split a note with default settings.

<video src="https://github.com/decaf-dev/obsidian-note-splitter/assets/40307803/b15117e8-a297-4353-b705-13e7713872ef" controls="controls" style="max-width: 100%;">
Your browser does not support the video tag.
</video>

Splitting a note with [Use content as title](#use-content-as-title) enabled
Split a note with [use first line as title](#use-first-line-as-title) enabled.

<video src="https://github.com/decaf-dev/obsidian-note-splitter/assets/40307803/fe4edb7c-4f4d-4f3e-b1a8-a42cd2a23706" controls="controls" style="max-width: 100%;">
Your browser does not support the video tag.
Expand All @@ -39,49 +39,55 @@ Splitting a note with [Use content as title](#use-content-as-title) enabled

## Usage

1. Open a note that you want to split
1. Open the note that you want to split
2. Switch to editing mode
3. Open the Obsidian command palette
4. Type **Split by delimiter**
5. Press enter
6. Your note is now split
6. See split notes in the [output folder](#output-folder)

>[!NOTE]
> Splitting a note will not modify the original note, unless the [delete original](#delete-original) setting is enabled. It will create new notes in an output folder that you specify.
> Splitting a note does not modify the original note.
### Frontmatter

When splitting a note, this plugin will ignore frontmatter. Only the content after the frontmatter block will be split.
When splitting a note, frontmater is ignored. Only content after the frontmatter block is split.

## Settings

### Folder path
### Output folder

Folder to save the split notes to. The default is `note-splitter`.
The folder to save split notes in. If empty, the folder of the original note will be used.

Setting this field to an empty string will save split notes to the same folder as the original note.
> [!NOTE]
> Default value is `note-splitter`
### Delimiter

The delimiter to split by can be configured in the plugin settings. The default delimiter is a new line `\n`.
The sequence of characters to split by. When you split a note, the content before and after each delimiter will become new notes.

> [!NOTE]
> Default value is a newline character `\n`
### Use first line as title

### Use content as title
If enabled, the first line of split content will be used as the title of the split note. If the title already exists, the conflict will be indicated by naming the note as `Split conflict <random-uuid>`.

If enabled, use the first line of the split section as the name for new notes, handling any name collisions automatically. If disabled, a timestamp is used.
If disabled, a timestamp will be used as the title e.g. `note-splitter-1702591910`.

> [!NOTE]
> Disabled by default.
### Delete original

If enabled, the original note will be deleted after the split.
If enabled, the original note will be deleted after a successful split.

> [!NOTE]
> Disabled by default.
## Contributing

Contributions are welcome. Please include a brief description of the changes you are making in your pull request.
Issues and pull requests are welcome.

## License

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": "note-splitter",
"name": "Note Splitter",
"version": "1.1.0",
"version": "1.1.1",
"minAppVersion": "0.15.0",
"description": "Split a note into individual notes based on a delimiter.",
"author": "DecafDev",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-note-splitter",
"version": "1.1.0",
"version": "1.1.1",
"description": "Split notes based on a delimiter",
"main": "main.js",
"scripts": {
Expand Down
22 changes: 11 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ export default class NoteSplitterPlugin extends Plugin {
return;
}

const splitLines = dataWithoutFrontmatter
const splitContent = dataWithoutFrontmatter
.split(delimiter)
.map((line) => line.trim())
.filter((line) => line !== "");
.map((content) => content.trim())
.filter((content) => content !== "");

if (splitLines.length === 0) {
if (splitContent.length === 0) {
new Notice("No content to split.");
return;
}

if (splitLines.length === 1) {
new Notice("Only one line found. Nothing to split.");
if (splitContent.length === 1) {
new Notice("Only one piece of content found. Nothing to split.");
return;
}

Expand All @@ -96,8 +96,8 @@ export default class NoteSplitterPlugin extends Plugin {
}

let filesCreated = 0;
for (const [i, line] of splitLines.entries()) {
let fileName = line;
for (const [i, content] of splitContent.entries()) {
let fileName = content.split("\n")[0];
if (this.settings.useContentAsTitle) {
fileName = escapeInvalidFileNameChars(fileName);
fileName = trimForFileName(fileName, ".md");
Expand All @@ -108,13 +108,13 @@ export default class NoteSplitterPlugin extends Plugin {
const filePath = normalizePath(`${folderPath}/${fileName}.md`);

try {
await this.app.vault.create(filePath, line);
await this.app.vault.create(filePath, content);
filesCreated++;
} catch (err) {
if (err.message.includes("already exists")) {
const newFilePath = `${folderPath}/Split conflict ${crypto.randomUUID()}.md`;
try {
await this.app.vault.create(newFilePath, line);
await this.app.vault.create(newFilePath, content);
filesCreated++;
} catch (err) {
console.error(err);
Expand All @@ -127,7 +127,7 @@ export default class NoteSplitterPlugin extends Plugin {
}
}

if (filesCreated === splitLines.length && this.settings.deleteOriginalNote) {
if (filesCreated === splitContent.length && this.settings.deleteOriginalNote) {
await this.app.vault.delete(file);
}

Expand Down
10 changes: 5 additions & 5 deletions src/obsidian/note-splitter-settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default class NoteSplitterSettingsTab extends PluginSettingTab {
containerEl.empty();

new Setting(containerEl)
.setName("Folder path")
.setName("Output folder")
.setDesc(
"The path to the folder that split notes will be placed in. If left empty, the folder of the original note will be used.",
"The folder to save split notes in. If empty, the folder of the original note will be used.",
)
.addText((text) =>
text.setValue(this.plugin.settings.saveFolderPath).onChange(async (value) => {
Expand All @@ -28,7 +28,7 @@ export default class NoteSplitterSettingsTab extends PluginSettingTab {

new Setting(containerEl)
.setName("Delimiter")
.setDesc("The delimiter to split by.")
.setDesc("The sequence of characters to split by.")
.addText((text) =>
text.setValue(this.plugin.settings.delimiter).onChange(async (value) => {
this.plugin.settings.delimiter = value;
Expand All @@ -37,9 +37,9 @@ export default class NoteSplitterSettingsTab extends PluginSettingTab {
);

new Setting(containerEl)
.setName("Use content as title")
.setName("Use first line as title")
.setDesc(
"If true, the first sentence will be used as the title of the note, otherwise a timestamp will be used e.g. note-splitter-1702591910.",
"If enabled, the first line of split content will be used as the title of the split note. If disabled, a timestamp will be used. e.g. note-splitter-1702591910",
)
.addToggle((text) =>
text.setValue(this.plugin.settings.useContentAsTitle).onChange(async (value) => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export const escapeInvalidFileNameChars = (value: string) => {
* Trims the string to the maximum length allowed for a file name
*/
export const trimForFileName = (value: string, extension: string) => {
const MAX_LENGTH_MAC_OS = 255;
return value.substring(0, MAX_LENGTH_MAC_OS - extension.length - 1);
const MAX_LENGTH = 255;
return value.substring(0, MAX_LENGTH - extension.length - 1);
};
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"0.5.1": "0.15.0",
"0.6.0": "0.15.0",
"1.0.0": "0.15.0",
"1.1.0": "0.15.0"
"1.1.0": "0.15.0",
"1.1.1": "0.15.0"
}

0 comments on commit 85e111c

Please sign in to comment.