# Fixed an issue where all the last updated dates were the same on Hugo blogs.

日本語版: 日本語で読む

Table of Contents

Last updated 1 minute ago

I updated the article, so when I visited the blog and read the articles, I noticed that all the articles were last updated at the same time.

Apparently, if you put lastmod in the article’s meta data, the last updated date will be updated, but I don’t want to do that every time.

Use Git

While researching there, I learned that it seems to be possible using the information of Git.

Configure the following settings with hugo.toml.

enableGitInfo = true [frontmatter] lastmod = ["lastmod", ":git", ":fileModTime",
":default"]

I built it with , but all the articles were last updated 1 minute ago and still remain the same.

I did a lot of research, and it seemed like it could be done by adding an option when building, so I executed it, but it didn’t change 1 minute before the last update.

Check out Git information

It was really strange, so I looked at the commit history of old .md and it was 1 minute ago.

When I tried to figure out why this happened, I discovered that the code was formatted using Github Action, which seemed to be the problem.

When I actually deleted Github Action, the last updated date was released.

Modify Github Action

Modify Action Flow created in I want to run prettier with Github Action.

In the previous Action Flow, all files were formatted, so I modified it to only format changed files.

New version (top):

Terminal window
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} -- '*.md')
if [[ -n "$CHANGED_FILES" ]]; then
echo "$CHANGED_FILES" | xargs prettier --write
else
echo "No Markdown files changed. Skipping formatting."
fi

Old version (bottom):

Terminal window
prettier --write "**/*.md"

Other improvements have also been made to make it more streamlined.

name: Format Markdown
on:
push:
branches:
- main
permissions:
contents: write
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install Prettier
run: |
npm install -g prettier
- name: Create .prettierrc
run: |
echo '{"overrides": [{"files": "*.md", "options": {"proseWrap": "always"}}]}' > .prettierrc
- name: Format only changed Markdown files
run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} -- '*.md')
if [[ -n "$CHANGED_FILES" ]]; then
echo "$CHANGED_FILES" | xargs prettier --write
else
echo "No Markdown files changed. Skipping formatting."
fi
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git diff --cached --quiet || (git commit -m "Format markdown files" && git push origin main)

In the end, it worked.


More Posts
My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


Comments