Skip to content

Commit

Permalink
Release v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
beaussan committed Jul 27, 2023
1 parent 210128e commit 901d56c
Show file tree
Hide file tree
Showing 14 changed files with 640 additions and 674 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Update time on edit plugin

This plugins update on save the metadata of the file with the time it was updated, and the time of creation if there is none (useful for new files).
The keys can be configured (by default `updated` and `created`).
This plugin update on save the metadata of the file with the time it was updated, and the time of creation if there is none (useful for new files).

**This is still an early version of the plugin, here is the current limitations :**
Here is a list of feature this plugin provides :
- Keep in sync the `mtime` (last modified time) in a property key (default to `updated`)
- Keep in sync the `ctime` (file creation time) in a property key (default to `created`)
- Customize the date format, default to obsidian date format for property display
- Ignore folder for all update, useful for template files
- Ignore folder for the creation property
- Works on mobile & desktop

The supported input date format are :
* timestamp number (ex: 628021800000)
* year only (ex: "2010")
* year and month only (ex: "2010-06")
* year, month and day (ex: "2010-06-09")
* ISO RFC 2822 format (ex : "2010-06-09T15:20:00Z", "2010-06-09T15:20:00-07:00")
* Non iso format (ex: "June 9, 2010", "2010 June 9", "6/9/2010 3:20 pm")

The only supported output is the [RFC 3339](https://tools.ietf.org/html/rfc3339) format (ex : "2019-09-18T19:00:52Z")
This plugin will read the `ctime` and `mtime` from obsidian, and thus, the file system. **If file change from an external source, the header keys will be updated**.

Remember to backup your vault since this plugin will modify files.
72 changes: 72 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';
import copy from 'esbuild-plugin-copy';
import { replace } from 'esbuild-plugin-replace';

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = process.argv[2] === 'production';

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'dist/main.js',
plugins: [
replace({
values: {
__DEV_MODE__: !prod,
},
exclude: /.*utils.ts/,
}),
copy({
resolveFrom: 'cwd',
assets: [
{
from: ['./manifest.json'],
to: ['./dist/manifest.json'],
},
{
from: ['./styles.css'],
to: ['./dist/styles.css'],
},
],
watch: true,
}),
],
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
18 changes: 9 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "update-time-on-edit",
"name": "Update time on edit",
"version": "1.1.2",
"minAppVersion": "0.10.11",
"description": "Keep front matter in sync with the last edit time",
"author": "@beaussan",
"authorUrl": "https://github.com/beaussan",
"isDesktopOnly": false
}
"id": "update-time-on-edit",
"name": "Update time on edit",
"version": "2.0.0",
"minAppVersion": "1.1.0",
"description": "Keep front matter in sync with the last edit time",
"author": "@beaussan",
"authorUrl": "https://github.com/beaussan",
"isDesktopOnly": false
}
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
{
"name": "obsidian-update-time-on-edit",
"version": "1.1.2",
"version": "2.0.0",
"description": "Keep the updated front matter header in sync with the last edit",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production",
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"format:write": "prettier --write \"**/*.{ts,json}\"",
"format:check": "prettier --list-different \"**/*.{ts,json}\""
},
"keywords": [],
"author": "@beaussan",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "27.0.2",
"@types/node": "^14.14.37",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"esbuild-copy-static-files": "^0.1.0",
"esbuild-plugin-copy": "^2.1.1",
"esbuild-plugin-replace": "^1.4.0",
"husky": "6.0.0",
"jest": "27.2.5",
"obsidian": "^0.12.17",
"obsidian": "^1.1.1",
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"rollup": "^2.32.1",
"rollup-plugin-copy": "3.4.0",
"ts-jest": "27.0.7",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"dependencies": {
"@popperjs/core": "2.10.2",
"date-fns": "2.21.1",
"gray-matter": "4.0.2",
"rxjs": "6.6.7"
},
"husky": {
Expand Down
39 changes: 0 additions & 39 deletions rollup.config.js

This file was deleted.

35 changes: 8 additions & 27 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ export interface UpdateTimeOnEditSettings {
enableCreateTime: boolean;
headerUpdated: string;
headerCreated: string;
minMinutesBetweenSaves: number;
// Union because of legacy
ignoreGlobalFolder?: string | string[];
ignoreCreatedFolder?: string[];
}

export const DEFAULT_SETTINGS: UpdateTimeOnEditSettings = {
dateFormat: "yyyy-MM-dd'T'HH:mm:ssxxx",
dateFormat: "yyyy-MM-dd'T'HH:mm",
enableCreateTime: true,
headerUpdated: 'updated',
headerCreated: 'created',
minMinutesBetweenSaves: 1,
ignoreGlobalFolder: [],
ignoreCreatedFolder: [],
};
Expand All @@ -41,18 +39,17 @@ export class UpdateTimeOnEditSettingsTab extends PluginSettingTab {
containerEl.createEl('h2', { text: 'Global settings' });

this.addExcludedFoldersSetting();
this.addTimeBetweenUpdates();
this.addDateFormat();

containerEl.createEl('h2', { text: 'Updated at' });

this.addFrontMatterUpdated();

containerEl.createEl('h2', { text: 'Created at' });

this.addEnableCreated();
this.addFrontMatterCreated();
this.addExcludedCreatedFoldersSetting();

containerEl.createEl('h2', { text: 'Updated at' });

this.addFrontMatterUpdated();
}

async saveSettings() {
Expand Down Expand Up @@ -86,6 +83,8 @@ export class UpdateTimeOnEditSettingsTab extends PluginSettingTab {
}),
descr.createEl('br'),
`Currently: ${format(new Date(), getValue())}`,
descr.createEl('br'),
`Obsidian default format for date properties: yyyy-MM-dd'T'HH:mm`,
);
return descr;
};
Expand All @@ -104,22 +103,6 @@ export class UpdateTimeOnEditSettingsTab extends PluginSettingTab {
);
}

addTimeBetweenUpdates(): void {
new Setting(this.containerEl)
.setName('Minimum number of minutes between update')
.setDesc('If your files are updating too often, increase this.')
.addSlider((slider) =>
slider
.setLimits(1, 30, 1)
.setValue(this.plugin.settings.minMinutesBetweenSaves)
.onChange(async (value) => {
this.plugin.settings.minMinutesBetweenSaves = value;
await this.saveSettings();
})
.setDynamicTooltip(),
);
}

addEnableCreated(): void {
new Setting(this.containerEl)
.setName('Enable the created front matter key update')
Expand All @@ -138,9 +121,7 @@ export class UpdateTimeOnEditSettingsTab extends PluginSettingTab {
addFrontMatterUpdated(): void {
new Setting(this.containerEl)
.setName('Front matter updated name')
.setDesc(
'The key in the front matter yaml for the update time. The time **must** be present.',
)
.setDesc('The key in the front matter yaml for the update time.')
.addText((text) =>
text
.setPlaceholder('updated')
Expand Down
10 changes: 0 additions & 10 deletions src/log.ts

This file was deleted.

Loading

0 comments on commit 901d56c

Please sign in to comment.