Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions .github/workflows/build-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 6 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}"
Expand All @@ -161,7 +161,7 @@ function createIndex(path, statsSync) {
} catch(e) {
console.error('Index error: ', path, e)
}
});
});
}

function getAllFilesRecursively(directoryPath) {
Expand All @@ -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)

}
}
}

Expand Down