Skip to content

Commit

Permalink
Merge pull request #1178 from pjkaufman/timestamp-update-after-file-c…
Browse files Browse the repository at this point in the history
…hange

Feat: Update Date Modified on Editor Content Change & Miscellaneous Style and YAML Timestamp Changes
  • Loading branch information
pjkaufman authored Sep 28, 2024
2 parents 096bd93 + c2282b2 commit 21856fc
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 83 deletions.
2 changes: 1 addition & 1 deletion __integration__/obsidian-mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function edgeCaseSetup(plugin: TestLinterPlugin, _: Editor): Promise<void> {
'enabled': true,
'date-created': true,
'date-created-key': 'created',
'force-retention-of-create-value': true,
'date-created-source-of-truth': 'file system',
'date-modified': true,
'date-modified-key': 'last_modified',
'format': 'YYYY-MM-DD',
Expand Down
130 changes: 123 additions & 7 deletions __tests__/yaml-timestamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ ruleTest({
format: 'dddd, MMMM Do YYYY, h:mm a ',
currentTime: moment('Thursday, January 2nd 2020, 12:01 am', 'dddd, MMMM Do YYYY, h:mm a'),
alreadyModified: false,
forceRetentionOfCreatedValue: false,
dateCreatedSourceOfTruth: 'frontmatter',
fileModifiedTime: '2020-01-02T00:00:00-00',
},
},
{
testName: 'When the date format changes and `forceRetentionOfCreatedValue = true`, date created value is based on the one in the YAML frontmatter.',
testName: 'When the date format changes and `dateCreatedSourceOfTruth = frontmatter`, date created value is based on the one in the YAML frontmatter.',
before: dedent`
---
created: Wednesday, January 1st 2020, 12:00:00 am
Expand All @@ -82,7 +82,7 @@ ruleTest({
options: {
dateModified: false,
dateCreatedKey: 'created',
forceRetentionOfCreatedValue: true,
dateCreatedSourceOfTruth: 'frontmatter',
format: 'YYYY, h:mm:ss a',
locale: 'en',
},
Expand Down Expand Up @@ -359,7 +359,7 @@ ruleTest({
},
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/745
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',
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',
before: dedent`
---
tag: tag1
Expand All @@ -383,11 +383,11 @@ ruleTest({
fileModifiedTime: '2020-02-04T18:00:00-00:00',
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
alreadyModified: false,
forceRetentionOfCreatedValue: true,
dateCreatedSourceOfTruth: 'frontmatter',
},
},
{
testName: 'When creation date exists and force retention of created date and convert to UTC are true, creation date should remain unchanged',
testName: 'When creation date exists and frontmatter is the source of truth and convert to UTC are true, creation date should remain unchanged',
before: dedent`
---
created: 2019-12-31T14:00:00+00:00
Expand All @@ -405,7 +405,7 @@ ruleTest({
dateModified: false,
fileCreatedTime: '2020-01-01T09:00:00-05:00', // 9 AM Eastern Standard Time
currentTime: moment('2020-01-01T21:00:05-05:00', 'YYYY-MM-DDTHH:mm:ssZ'), // 9:00:05 PM EST, same day
forceRetentionOfCreatedValue: true,
dateCreatedSourceOfTruth: 'frontmatter',
convertToUTC: true,
},
},
Expand Down Expand Up @@ -435,5 +435,121 @@ ruleTest({
convertToUTC: true,
},
},
{
testName: 'When changes are made prior to the YAML timestamp rule and user and Linter edits are the source of truth, update date modified',
before: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:00 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
after: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:07 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
options: {
dateCreatedKey: 'created',
dateModifiedKey: 'modified',
fileCreatedTime: '2020-01-01T00:00:00-00:00',
fileModifiedTime: '2020-02-04T18:00:00-00:00',
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
alreadyModified: true,
dateCreatedSourceOfTruth: 'frontmatter',
dateModifiedSourceOfTruth: 'user or Linter edits',
},
},
{
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',
before: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:00 pm
created: Wednesday, January 1st 2020, 12:00 am
location: "path"
---
`,
after: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:07 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
options: {
dateCreatedKey: 'created',
dateModifiedKey: 'modified',
fileCreatedTime: '2020-01-01T00:00:00-00:00',
fileModifiedTime: '2020-02-04T18:00:00-00:00',
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
alreadyModified: false,
dateCreatedSourceOfTruth: 'frontmatter',
dateModifiedSourceOfTruth: 'user or Linter edits',
},
},
{
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',
before: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
after: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:07 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
options: {
dateCreatedKey: 'created',
dateModifiedKey: 'modified',
fileCreatedTime: '2020-01-01T00:00:00-00:00',
fileModifiedTime: '2020-02-04T18:00:00-00:00',
currentTime: moment('Tuesday, February 4th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
alreadyModified: false,
dateCreatedSourceOfTruth: 'frontmatter',
dateModifiedSourceOfTruth: 'user or Linter edits',
},
},
{
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',
before: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:00 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
after: dedent`
---
tag: tag1
modified: Tuesday, February 4th 2020, 6:00:00 pm
created: Wednesday, January 1st 2020, 12:00:00 am
location: "path"
---
`,
options: {
dateCreatedKey: 'created',
dateModifiedKey: 'modified',
fileCreatedTime: '2020-01-01T00:00:00-00:00',
fileModifiedTime: '2020-02-05T18:00:00-00:00',
currentTime: moment('Tuesday, February 5th 2020, 6:00:07 pm', 'dddd, MMMM Do YYYY, h:mm:ss a'),
alreadyModified: false,
dateCreatedSourceOfTruth: 'frontmatter',
dateModifiedSourceOfTruth: 'user or Linter edits',
},
},
],
});
4 changes: 0 additions & 4 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,6 @@ export default {
'name': 'Schlüssel für das Erstellungsdatum',
'description': 'Der YAML-Schlüssel, der für das Erstellungsdatum verwendet werden soll',
},
'force-retention-of-create-value': {
'name': 'Erzwinge die Beibehaltung des Schlüsselwertes für das Erstellungsdatum',
'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.',
},
'date-modified': {
'name': 'Änderungsdatum',
'description': 'Geben Sie das Datum ein, an dem die Datei zuletzt geändert wurde',
Expand Down
32 changes: 27 additions & 5 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default {
'plugin-unload': 'Unloading plugin',
'folder-lint': 'Linting folder ',
'linter-run': 'Running linter',
'file-change-yaml-lint-run': 'Running editor content change YAML linting',
'file-change-yaml-lint-skipped': 'No file change detected, so YAML linting skipped',
'file-change-yaml-lint-warning': 'No file info is present, but debounce ran. Something went wrong somewhere.',
'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.',
'see-console': 'See console for more details.',
'unknown-error': 'An unknown error occurred during linting.',
Expand Down Expand Up @@ -142,12 +145,16 @@ export default {
'description': 'Display the number of characters changed after linting',
},
'lint-on-file-change': {
'name': 'Lint on File Change',
'name': 'Lint on Focused File Change',
'description': 'When the a file is closed or a new file is swapped to, the previous file is linted.',
},
'display-lint-on-file-change-message': {
'name': 'Display Lint on File Change Message',
'description': 'Displays a message when `Lint on File Change` occurs',
'description': 'Displays a message when `Lint on Focused File Change` occurs',
},
'timestamp-update-on-file-contents-updated': {
'name': 'Update YAML Timestamp on File Contents Update',
'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.',
},
'folders-to-ignore': {
'name': 'Folders to ignore',
Expand Down Expand Up @@ -806,9 +813,13 @@ export default {
'name': 'Date Created Key',
'description': 'Which YAML key to use for creation date',
},
'force-retention-of-create-value': {
'name': 'Force Date Created Key Value Retention',
'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.',
'date-created-source-of-truth': {
'name': 'Date Created Source of Truth',
'description': 'Specifies where to get the date created value from if it is already present in the frontmatter.',
},
'date-modified-source-of-truth': {
'name': 'Date Modified Source of Truth',
'description': 'Specifies what way should be used to determine when the date modified should be updated if it is already present in the frontmatter.',
},
'date-modified': {
'name': 'Date Modified',
Expand Down Expand Up @@ -904,6 +915,17 @@ export default {
'first-h1': 'First H1',
'first-h1-or-filename-if-h1-missing': 'First H1 or Filename if H1 is Missing',
'filename': 'Filename',
// settings-data.ts
'never': 'Never',
'after 5 seconds': 'After 5 seconds',
'after 10 seconds': 'After 10 seconds',
'after 15 seconds': 'After 15 seconds',
'after 30 seconds': 'After 30 seconds',
'after 1 minute': 'After 1 minute',
// yaml-timestamp.ts
'file system': 'File system',
'frontmatter': 'YAML frontmatter',
'user or Linter edits': 'Changes in Obsidian',
// quote-style.ts
'\'\'': '\'\'', // leave as is
'‘’': '‘’', // leave as is
Expand Down
4 changes: 0 additions & 4 deletions src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,6 @@ export default {
'name': 'Clave de fecha de creación',
'description': 'La clave de YAML para usar para la fecha de creación',
},
'force-retention-of-create-value': {
'name': 'Forzar la fecha de creación de la retención del valor clave',
'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.',
},
'date-modified': {
'name': 'Fecha modificada',
'description': 'Inserte la fecha en que se modificó el archivo por última vez',
Expand Down
4 changes: 0 additions & 4 deletions src/lang/locale/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,6 @@ export default {
'name': 'Oluşturma Tarihi Anahtarı',
'description': 'Oluşturma tarihi için hangi YAML anahtarını kullanacağı',
},
'force-retention-of-create-value': {
'name': 'Oluşturma Tarihi Anahtar Değerinin Korunmasını Zorla',
'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.',
},
'date-modified': {
'name': 'Değiştirme Tarihi',
'description': 'Dosyanın son değiştirildiği tarihi ekler',
Expand Down
4 changes: 0 additions & 4 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,6 @@ export default {
'name': '创建日期键名',
'description': '使用哪个 YAML 键来表示创建日期',
},
'force-retention-of-create-value': {
'name': '强制保留创建日期值',
'description': '沿用 YAML Front-matter 中已有的创建日期,忽略文档元数据。对于文档元数据更改(比如复制文件)导致的创建时间更改非常有用',
},
'date-modified': {
'name': '修改日期',
'description': '插入文件的最近一次的修改日期',
Expand Down
Loading

0 comments on commit 21856fc

Please sign in to comment.