Skip to content

Commit

Permalink
fix: fixed workflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
toFrankie committed Aug 11, 2024
1 parent d4702e0 commit 4cb9bde
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-traffic-views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- cron: '0 */4 * * *'

jobs:
update-badge:
update-traffic-views:
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/traffic-views.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions scripts/update-traffic-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ import { getTrafficViews } from './common.js'

dotenv.config()

async function updateBadge(templatePath, outputPath, newCount) {
async function updateBadgeSvg(templatePath, outputPath, newCount) {
const originalBadgeContent = await fs.readFile(outputPath, 'utf8')

const templateBadgeContent = await fs.readFile(templatePath, 'utf8')
const currentBadgeContent = templateBadgeContent.replace(/{{views}}/, newCount)

if (currentBadgeContent !== originalBadgeContent) {
await fs.writeFile(outputPath, currentBadgeContent, 'utf8')
console.log('badge.svg has been updated.')
console.log('traffic-views.svg has been updated.')
return true
}

console.log('No changes detected in badge.svg.')
console.log('No changes detected in traffic-views.svg.')
return false
}

//
;(async function main() {
const totalCount = await getTrafficViews()

const templateBadgePath = path.resolve('docs/templates/badge.svg')
const outputBadgePath = path.resolve('docs/badge.svg')
const templateBadgePath = path.resolve('docs/templates/traffic-views.svg')
const outputBadgePath = path.resolve('docs/traffic-views.svg')

const isUpdated = await updateBadge(templateBadgePath, outputBadgePath, totalCount)
const isUpdated = await updateBadgeSvg(templateBadgePath, outputBadgePath, totalCount)

if (!isUpdated) {
console.log('No update needed.')
Expand Down

0 comments on commit 4cb9bde

Please sign in to comment.