diff --git a/.github/workflows/build-search.yaml b/.github/workflows/build-search.yaml index 54d2407..505ed30 100644 --- a/.github/workflows/build-search.yaml +++ b/.github/workflows/build-search.yaml @@ -19,19 +19,22 @@ concurrency: group: "pages" cancel-in-progress: false - jobs: buildSearch: runs-on: ubuntu-latest + if: ${{ ! contains(github.event.head_commit.message, 'Automate update') }} steps: - - uses: actions/checkout@v2 - + - uses: actions/checkout@v4 # Uses the private access token from above link with: + fetch-depth: 0 token: ${{ secrets.GH_SUBMODULE_SECRET }} + - name: Restore timestamps + uses: chetan/git-restore-mtime-action@v1 + - name: Pull latest changes - run: git pull origin main + run: git pull origin main -X theirs - name: Setup Node.js uses: actions/setup-node@v4 @@ -44,23 +47,11 @@ jobs: - name: Build search run: npm run search - # Check if there are any changes before attempting to commit and push changes - - name: Check for changes - id: check_changes - run: | - git diff --exit-code - if [ $? -eq 0 ]; then - echo "No changes to commit." - echo "::set-output name=changes::false" - else - echo "::set-output name=changes::true" - fi - - name: Commit & push changes run: | git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions - build search index" git status git add . - git commit -m "Update site-search-data.json" - git push origin main + git commit -m "Automate update site-search-data.json" + git push origin main \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 9e39c0e..a6c835a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -146,7 +146,7 @@ function createIndex(path, statsSync) { if (h.textContent != 'Table of Contents' && !searchDict[title+urlPath]) { content += `{ "title": "${title}", - "mod": "${statsSync.mtime}", + "mod": "${statsSync.trim()}", "tag": "${tag}", "tagId": "${h.getAttribute('id')}", "path": "/${urlPath.replace('.md', '.html')}" @@ -161,7 +161,7 @@ function createIndex(path, statsSync) { } catch(e) { console.error('Index error: ', path, e) } - }); + }); } function getAllFilesRecursively(directoryPath) { @@ -183,16 +183,14 @@ function getAllFilesRecursively(directoryPath) { for (let f of filePaths) { if ( f.indexOf('.html') > -1 || f.indexOf('.md') > -1 ) { - let statsSync = {} try { - statsSync = fs.statSync(f) + exec('git log -1 --format="%ad" -- '+f, (error, stdout, stderr) => { + createIndex(f, stdout) + }) } catch (err) { console.error('Error getting file stats synchronously:', err); - } - - createIndex(f, statsSync) - + } } }