Welcome to the visitor-badge
repository by Arman Kianian! This guide will help you set up and use the visitor badge to track visits to your GitHub repository. Let's get started! π
Before you begin, make sure you have:
- A GitHub account
- A repository where you want to add the visitor badge
- Basic knowledge of Git and GitHub
First, fork the visitor-badge repository to your GitHub account.
Next, clone the forked repository to your local machine:
git clone https://github.com/<your-username>/visitor-badge.git
cd visitor-badge
Ensure you have a visits.txt
file in the root of your repository to track the visit count. If it doesn't exist, create it:
echo "0" > visits.txt
Update your README.md
file to include the visit badge. Add the following line where you want the badge to appear:
![Visits](https://img.shields.io/badge/Visits-15850-blue)
Create a workflow file to automate visit count updates. Create a directory .github/workflows
in your repository if it doesn't already exist, then create a file named update-visits.yml
:
name: Update Visits
on:
push:
branches:
- main
schedule:
- cron: '*/15 * * * *' # Runs every 15 minutes
jobs:
update-visits:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Increment visit counter
id: increment
run: |
if [ ! -f visits.txt ]; then echo "0" > visits.txt; fi
visits=$(cat visits.txt)
visits=$((visits + 1))
echo $visits > visits.txt
echo "::set-output name=visits::$visits"
- name: Update README.md
run: |
visits=${{ steps.increment.outputs.visits }}
badge="![Visits](https://img.shields.io/badge/Visits-15850-blue)"
sed -i 's|!\[Visits\](https://img.shields.io/badge/Visits-.*-blue)|'"$badge"'|' README.md
- name: Commit changes
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
git add visits.txt README.md
git commit -m 'Update visits count'
git push
Commit and push the changes to your GitHub repository:
git add visits.txt README.md .github/workflows/update-visits.yml
git commit -m "Set up visit tracking workflow"
git push origin main
Once everything is set up, your visit count will be updated automatically every 15 minutes. You can view the visit badge in your README.md
:
You have successfully set up the visitor badge in your repository! Now you can track how many people visit your GitHub project. Happy coding! π»