Jekyll updating File.mtime on each build

Viewed 20

I have a Jekyll site hosted on Github pages. Each post shows its last modified date, which I update by running a Jekyll hook to access the File.mtime property. All dates are correct when running the site locally, but as soon as I push my changes to Github, all dates change to the time the commit was made. I run the following pre-push hook to build and push the contents of the _site folder to the gh_pages branch:

#!/bin/sh

# If any command fails in the bellow script, exit with error
set -e

# Set the name of the folder that will be created in the parent
# folder of your repo folder, and which will temporarily
# hold the generated content.
temp_folder="_gh-pages-temp"

# Make sure our main code runs only if we push the master branch
if [ "$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)" == "master" ]; then
    # Store the last commit message from master branch
    last_message=$(git show -s --format=%s master)

    # Build our Jekyll site
    jekyll build

    # Move the generated site in our temp folder
    mv _site ../${temp_folder}

    # Checkout the gh-pages branch and clean it's contents
    git checkout gh-pages
    rm -rf *

    # Copy the site content from the temp folder and remove the temp folder
    cp -r ../${temp_folder}/* .
    rm -rf ../${temp_folder}

    # Commit and push our generated site to GitHub
    git add -A
    git commit -m "Built \`$last_message\`"
    git push

    # Go back to the master branch
    git checkout master
else
    echo "Not master branch. Skipping build"
fi

The last_modified_date property for each post is updated by the following Jekyll hook:

Jekyll::Hooks.register :site, :pre_render do |site|
    site.collections['notes'].docs.each do |note|
        # get the current post last modified time
        modification_time = File.mtime( note.path )
  
        # inject modification_time in post's datas.
        note.data['last_modified_date'] = modification_time
    end
end

I don't understand why this is happening. I thought enabling incremental build will fix this issue, but that didn't work.

0 Answers
Related