diff --git a/.github/workflows/fetch-commit-dates.yml b/.github/workflows/fetch-commit-dates.yml new file mode 100644 index 0000000..288ddaa --- /dev/null +++ b/.github/workflows/fetch-commit-dates.yml @@ -0,0 +1,32 @@ +name: fetch-commit-dates + +on: + push: + branches: + - main + paths-ignore: + - '_data/commit_dates.json' + +jobs: + + fetch-commit-dates: + if: ${{ !startsWith(github.event.head_commit.committer.name, 'GitHub Actions') }} + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required to get full commit history + + - name: Run Ruby script + run: ruby fetch-commit-dates.rb + + - name: Create pull request + uses: peter-evans/create-pull-request@v6 + with: + commit-message: "Update file dates" + title: "[auto] Update file dates" + body: "Automated action to update modified file dates to the latest commit date." + branch: "actions/update-file-dates" + base: main \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 206857c..77e4e26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Docs0 Changelog +## 1.0.3 (2024-03-09) +- Add automatic file modified date + ## 1.0.2 (2024-03-08) - Add unlisted property diff --git a/README.md b/README.md index 049a1c3..c9295ea 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ Parameters: - **draft:** (optional) set ***true*** to show a notice that the document is not completed (note that this notice appears automatically if the document is empty or if it contains a <todo></todo> tag. Set ***nodraft: true*** to avoid displaying the notice. - **date:** set the creation date of the document. - **modified:** set the date of the last modification of the document. +> Note that the last modified date is automatically updated when the document is modified and pushed to the repository. Use this parameter only if you need to set a specific date. - **order:** set a string to be used to sort the document in the navigation menu - check existing files to know how sorting works. In general, if the page is the child of a node, it is necessary to insert the order attribute of the parent node plus a slash ***/*** and a number (if you want to give a static position) or a sanitized version of the title (without spaces and special characters - if you want to use alphabetical sorting). Note that numbers come before letters (as they are placed before in the ASCII table); if you want that they are placed after letters, you need to enclose them in curly braces: e.g. ***zzz*** is after ***01*** but before ***{01}***. - **toc:** (optional) set ***false*** to hide the automatic table of contents. - **toc_h_min:** (optional) set the minimum heading level to include in the table of contents. This setting is set at the site level in the `_config.yml`. Default is 2. diff --git a/_includes/article.html b/_includes/article.html index 5a0d920..1b48620 100644 --- a/_includes/article.html +++ b/_includes/article.html @@ -31,7 +31,11 @@ {% if page.modified %} {{ page.modified | date: "%b %d, %Y" }} {% else %} - {{ page.date | date: "%b %d, %Y" }} + {% if site.data.commit_dates[page.path] %} + {{ site.data.commit_dates[page.path] | date: "%b %d, %Y" }} + {% else %} + {{ page.date | date: "%b %d, %Y" }} + {% endif %} {% endif %} {% endif %} diff --git a/fetch-commit-dates.rb b/fetch-commit-dates.rb new file mode 100644 index 0000000..b203d3f --- /dev/null +++ b/fetch-commit-dates.rb @@ -0,0 +1,15 @@ +require 'json' +require 'fileutils' + +# Create _data folder if it doesn't exist +data_folder = '_data' +Dir.mkdir(data_folder) unless File.exists?(data_folder) + +last_commits = {} +`git ls-files -- '*.md'`.each_line do |file| + file.chomp! + commit_date = `git log -1 --format='%ad' --date=iso -- "#{file}"`.chomp + last_commits[file] = commit_date +end + +File.write(File.join(data_folder, 'commit_dates.json'), JSON.pretty_generate(last_commits)) diff --git a/package.json b/package.json index b4ebf49..e9238f6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Docs0", - "version": "1.0.2", - "lastUpdated": "2024-03-08", + "version": "1.0.3", + "lastUpdated": "2024-03-09", "scripts": { "run (incremental)": "bundle exec jekyll serve --incremental --port 4001", "run (full)": "bundle exec jekyll serve --port 4001"