Skip to content

Commit 21856fc

Browse files
authored
Merge pull request #1178 from pjkaufman/timestamp-update-after-file-change
Feat: Update Date Modified on Editor Content Change & Miscellaneous Style and YAML Timestamp Changes
2 parents 096bd93 + c2282b2 commit 21856fc

File tree

17 files changed

+410
-83
lines changed

17 files changed

+410
-83
lines changed

__integration__/obsidian-mode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor): Promise<void> {
3737
'enabled': true,
3838
'date-created': true,
3939
'date-created-key': 'created',
40-
'force-retention-of-create-value': true,
40+
'date-created-source-of-truth': 'file system',
4141
'date-modified': true,
4242
'date-modified-key': 'last_modified',
4343
'format': 'YYYY-MM-DD',

__tests__/yaml-timestamp.test.ts

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ ruleTest({
6363
format: 'dddd, MMMM Do YYYY, h:mm a ',
6464
currentTime: moment('Thursday, January 2nd 2020, 12:01 am', 'dddd, MMMM Do YYYY, h:mm a'),
6565
alreadyModified: false,
66-
forceRetentionOfCreatedValue: false,
66+
dateCreatedSourceOfTruth: 'frontmatter',
6767
fileModifiedTime: '2020-01-02T00:00:00-00',
6868
},
6969
},
7070
{
71-
testName: 'When the date format changes and `forceRetentionOfCreatedValue = true`, date created value is based on the one in the YAML frontmatter.',
71+
testName: 'When the date format changes and `dateCreatedSourceOfTruth = frontmatter`, date created value is based on the one in the YAML frontmatter.',
7272
before: dedent`
7373
---
7474
created: Wednesday, January 1st 2020, 12:00:00 am
@@ -82,7 +82,7 @@ ruleTest({
8282
options: {
8383
dateModified: false,
8484
dateCreatedKey: 'created',
85-
forceRetentionOfCreatedValue: true,
85+
dateCreatedSourceOfTruth: 'frontmatter',
8686
format: 'YYYY, h:mm:ss a',
8787
locale: 'en',
8888
},
@@ -359,7 +359,7 @@ ruleTest({
359359
},
360360
},
361361
{ // accounts for https://github.com/platers/obsidian-linter/issues/745
362-
testName: 'When no changes are made, and force retention of creation date is active, do not update date modified when no change in modification time has been made',
362+
testName: 'When no changes are made, and frontmatter is the source of truth, do not update date modified when no change in modification time has been made',
363363
before: dedent`
364364
---
365365
tag: tag1
@@ -383,11 +383,11 @@ ruleTest({
383383
fileModifiedTime: '2020-02-04T18:00:00-00:00',
384384
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
385385
alreadyModified: false,
386-
forceRetentionOfCreatedValue: true,
386+
dateCreatedSourceOfTruth: 'frontmatter',
387387
},
388388
},
389389
{
390-
testName: 'When creation date exists and force retention of created date and convert to UTC are true, creation date should remain unchanged',
390+
testName: 'When creation date exists and frontmatter is the source of truth and convert to UTC are true, creation date should remain unchanged',
391391
before: dedent`
392392
---
393393
created: 2019-12-31T14:00:00+00:00
@@ -405,7 +405,7 @@ ruleTest({
405405
dateModified: false,
406406
fileCreatedTime: '2020-01-01T09:00:00-05:00', // 9 AM Eastern Standard Time
407407
currentTime: moment('2020-01-01T21:00:05-05:00', 'YYYY-MM-DDTHH:mm:ssZ'), // 9:00:05 PM EST, same day
408-
forceRetentionOfCreatedValue: true,
408+
dateCreatedSourceOfTruth: 'frontmatter',
409409
convertToUTC: true,
410410
},
411411
},
@@ -435,5 +435,121 @@ ruleTest({
435435
convertToUTC: true,
436436
},
437437
},
438+
{
439+
testName: 'When changes are made prior to the YAML timestamp rule and user and Linter edits are the source of truth, update date modified',
440+
before: dedent`
441+
---
442+
tag: tag1
443+
modified: Tuesday, February 4th 2020, 6:00:00 pm
444+
created: Wednesday, January 1st 2020, 12:00:00 am
445+
location: "path"
446+
---
447+
`,
448+
after: dedent`
449+
---
450+
tag: tag1
451+
modified: Tuesday, February 4th 2020, 6:00:07 pm
452+
created: Wednesday, January 1st 2020, 12:00:00 am
453+
location: "path"
454+
---
455+
`,
456+
options: {
457+
dateCreatedKey: 'created',
458+
dateModifiedKey: 'modified',
459+
fileCreatedTime: '2020-01-01T00:00:00-00:00',
460+
fileModifiedTime: '2020-02-04T18:00:00-00:00',
461+
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
462+
alreadyModified: true,
463+
dateCreatedSourceOfTruth: 'frontmatter',
464+
dateModifiedSourceOfTruth: 'user or Linter edits',
465+
},
466+
},
467+
{
468+
testName: 'When no changes are made prior to the YAML timestamp rule, the created date format is different from the current format in settings, and user and Linter edits are the source of truth, update date modified',
469+
before: dedent`
470+
---
471+
tag: tag1
472+
modified: Tuesday, February 4th 2020, 6:00:00 pm
473+
created: Wednesday, January 1st 2020, 12:00 am
474+
location: "path"
475+
---
476+
`,
477+
after: dedent`
478+
---
479+
tag: tag1
480+
modified: Tuesday, February 4th 2020, 6:00:07 pm
481+
created: Wednesday, January 1st 2020, 12:00:00 am
482+
location: "path"
483+
---
484+
`,
485+
options: {
486+
dateCreatedKey: 'created',
487+
dateModifiedKey: 'modified',
488+
fileCreatedTime: '2020-01-01T00:00:00-00:00',
489+
fileModifiedTime: '2020-02-04T18:00:00-00:00',
490+
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
491+
alreadyModified: false,
492+
dateCreatedSourceOfTruth: 'frontmatter',
493+
dateModifiedSourceOfTruth: 'user or Linter edits',
494+
},
495+
},
496+
{
497+
testName: 'When no changes are made prior to the YAML timestamp rule, the modified date format is different from the current format in settings, and user and Linter edits are the source of truth, update date modified',
498+
before: dedent`
499+
---
500+
tag: tag1
501+
modified: Tuesday, February 4th 2020, 6:00 pm
502+
created: Wednesday, January 1st 2020, 12:00:00 am
503+
location: "path"
504+
---
505+
`,
506+
after: dedent`
507+
---
508+
tag: tag1
509+
modified: Tuesday, February 4th 2020, 6:00:07 pm
510+
created: Wednesday, January 1st 2020, 12:00:00 am
511+
location: "path"
512+
---
513+
`,
514+
options: {
515+
dateCreatedKey: 'created',
516+
dateModifiedKey: 'modified',
517+
fileCreatedTime: '2020-01-01T00:00:00-00:00',
518+
fileModifiedTime: '2020-02-04T18:00:00-00:00',
519+
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
520+
alreadyModified: false,
521+
dateCreatedSourceOfTruth: 'frontmatter',
522+
dateModifiedSourceOfTruth: 'user or Linter edits',
523+
},
524+
},
525+
{
526+
testName: 'When no changes are made prior to the YAML timestamp rule, the file system date modified is more than 5 seconds different from the date modified, and user and Linter edits are the source of truth, do not update date modified',
527+
before: dedent`
528+
---
529+
tag: tag1
530+
modified: Tuesday, February 4th 2020, 6:00:00 pm
531+
created: Wednesday, January 1st 2020, 12:00:00 am
532+
location: "path"
533+
---
534+
`,
535+
after: dedent`
536+
---
537+
tag: tag1
538+
modified: Tuesday, February 4th 2020, 6:00:00 pm
539+
created: Wednesday, January 1st 2020, 12:00:00 am
540+
location: "path"
541+
---
542+
`,
543+
options: {
544+
dateCreatedKey: 'created',
545+
dateModifiedKey: 'modified',
546+
fileCreatedTime: '2020-01-01T00:00:00-00:00',
547+
fileModifiedTime: '2020-02-05T18:00:00-00:00',
548+
currentTime: moment('Tuesday, February 5th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
549+
alreadyModified: false,
550+
dateCreatedSourceOfTruth: 'frontmatter',
551+
dateModifiedSourceOfTruth: 'user or Linter edits',
552+
},
553+
},
438554
],
439555
});

src/lang/locale/de.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,6 @@ export default {
690690
'name': 'Schlüssel für das Erstellungsdatum',
691691
'description': 'Der YAML-Schlüssel, der für das Erstellungsdatum verwendet werden soll',
692692
},
693-
'force-retention-of-create-value': {
694-
'name': 'Erzwinge die Beibehaltung des Schlüsselwertes für das Erstellungsdatum',
695-
'description': 'Verwendet den Wert im YAML-Frontmatter für das Erstellungsdatum anstelle den Dateimetadaten, was nützlich ist, um zu verhindern, dass Änderungen an Dateimetadaten dazu führen, dass der Wert in einen anderen Wert geändert wird.',
696-
},
697693
'date-modified': {
698694
'name': 'Änderungsdatum',
699695
'description': 'Geben Sie das Datum ein, an dem die Datei zuletzt geändert wurde',

src/lang/locale/en.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export default {
4545
'plugin-unload': 'Unloading plugin',
4646
'folder-lint': 'Linting folder ',
4747
'linter-run': 'Running linter',
48+
'file-change-yaml-lint-run': 'Running editor content change YAML linting',
49+
'file-change-yaml-lint-skipped': 'No file change detected, so YAML linting skipped',
50+
'file-change-yaml-lint-warning': 'No file info is present, but debounce ran. Something went wrong somewhere.',
4851
'paste-link-warning': 'aborted paste lint as the clipboard content is a link and doing so will avoid conflicts with other plugins that modify pasting.',
4952
'see-console': 'See console for more details.',
5053
'unknown-error': 'An unknown error occurred during linting.',
@@ -142,12 +145,16 @@ export default {
142145
'description': 'Display the number of characters changed after linting',
143146
},
144147
'lint-on-file-change': {
145-
'name': 'Lint on File Change',
148+
'name': 'Lint on Focused File Change',
146149
'description': 'When the a file is closed or a new file is swapped to, the previous file is linted.',
147150
},
148151
'display-lint-on-file-change-message': {
149152
'name': 'Display Lint on File Change Message',
150-
'description': 'Displays a message when `Lint on File Change` occurs',
153+
'description': 'Displays a message when `Lint on Focused File Change` occurs',
154+
},
155+
'timestamp-update-on-file-contents-updated': {
156+
'name': 'Update YAML Timestamp on File Contents Update',
157+
'description': 'When the currently active file is modified, `YAML Timestamp` is run on the file. This should update the modified file timestamp if it is more than 5 seconds off from the current value.',
151158
},
152159
'folders-to-ignore': {
153160
'name': 'Folders to ignore',
@@ -806,9 +813,13 @@ export default {
806813
'name': 'Date Created Key',
807814
'description': 'Which YAML key to use for creation date',
808815
},
809-
'force-retention-of-create-value': {
810-
'name': 'Force Date Created Key Value Retention',
811-
'description': 'Reuses the value in the YAML frontmatter for date created instead of the file metadata which is useful for preventing file metadata changes from causing the value to change to a different value.',
816+
'date-created-source-of-truth': {
817+
'name': 'Date Created Source of Truth',
818+
'description': 'Specifies where to get the date created value from if it is already present in the frontmatter.',
819+
},
820+
'date-modified-source-of-truth': {
821+
'name': 'Date Modified Source of Truth',
822+
'description': 'Specifies what way should be used to determine when the date modified should be updated if it is already present in the frontmatter.',
812823
},
813824
'date-modified': {
814825
'name': 'Date Modified',
@@ -904,6 +915,17 @@ export default {
904915
'first-h1': 'First H1',
905916
'first-h1-or-filename-if-h1-missing': 'First H1 or Filename if H1 is Missing',
906917
'filename': 'Filename',
918+
// settings-data.ts
919+
'never': 'Never',
920+
'after 5 seconds': 'After 5 seconds',
921+
'after 10 seconds': 'After 10 seconds',
922+
'after 15 seconds': 'After 15 seconds',
923+
'after 30 seconds': 'After 30 seconds',
924+
'after 1 minute': 'After 1 minute',
925+
// yaml-timestamp.ts
926+
'file system': 'File system',
927+
'frontmatter': 'YAML frontmatter',
928+
'user or Linter edits': 'Changes in Obsidian',
907929
// quote-style.ts
908930
'\'\'': '\'\'', // leave as is
909931
'‘’': '‘’', // leave as is

src/lang/locale/es.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,6 @@ export default {
606606
'name': 'Clave de fecha de creación',
607607
'description': 'La clave de YAML para usar para la fecha de creación',
608608
},
609-
'force-retention-of-create-value': {
610-
'name': 'Forzar la fecha de creación de la retención del valor clave',
611-
'description': 'Reutiliza el valor en el frontmatter del YAML para la fecha de creación en lugar de los metadatos del archivo, lo que es útil para evitar que los cambios en los metadatos del archivo provoquen que el valor cambie a un valor diferente.',
612-
},
613609
'date-modified': {
614610
'name': 'Fecha modificada',
615611
'description': 'Inserte la fecha en que se modificó el archivo por última vez',

src/lang/locale/tr.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,6 @@ export default {
686686
'name': 'Oluşturma Tarihi Anahtarı',
687687
'description': 'Oluşturma tarihi için hangi YAML anahtarını kullanacağı',
688688
},
689-
'force-retention-of-create-value': {
690-
'name': 'Oluşturma Tarihi Anahtar Değerinin Korunmasını Zorla',
691-
'description': 'Dosya metadatası yerine YAML ön maddesindeki tarihi yeniden kullanır, bu da dosya metadatasındaki değişikliklerin değerin farklı bir değere değişmesine neden olmasını önler.',
692-
},
693689
'date-modified': {
694690
'name': 'Değiştirme Tarihi',
695691
'description': 'Dosyanın son değiştirildiği tarihi ekler',

src/lang/locale/zh-cn.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,6 @@ export default {
750750
'name': '创建日期键名',
751751
'description': '使用哪个 YAML 键来表示创建日期',
752752
},
753-
'force-retention-of-create-value': {
754-
'name': '强制保留创建日期值',
755-
'description': '沿用 YAML Front-matter 中已有的创建日期,忽略文档元数据。对于文档元数据更改(比如复制文件)导致的创建时间更改非常有用',
756-
},
757753
'date-modified': {
758754
'name': '修改日期',
759755
'description': '插入文件的最近一次的修改日期',

0 commit comments

Comments
 (0)