I have a problem fetching data from codeforces to my github profile I can't add a js code to the readme.md file to fetch data from codeforces When I'm trying to write a js code like this it appears as a text.
<script>
fetch('https://codeforces.com/api/user.status?handle=sadeen&from=1&count=10').then(response => response.json()).then(characters => showCharacters(characters.results));
showCharacters = characters => {
const charactersDiv = document.querySelector(‘#rick-and-morty- characters’);
characters.forEach(character => {
const characterElement = document.createElement(‘p’);
characterElement.innerText = `Character Name: ${character.name}`;
charactersDiv.append(characterElement);
});
}
</script>
You would not call a javascript program directly from a profile README.md
.
But you can set up a GitHub Action to update said README.md
, and that action can call anything.
See for instance " Self-updating GitHub Profile README with JavaScript " by Dan Curtis .
GitHub recently released a feature that allows users to add markdown to their profile.
People have done some pretty cool things, which inspired me to create a README that dynamically updates with my Dev.to posts.
GitHub Actions and NodeJS make this easy.
I created a script to:
- Get my Dev.to articles
- Parse my
README
- Update the
README
with my latest articlesYou'll need 3 files: .github/workflows/build.yaml, updateReadme.js, and README.md
Example of .github/workflows/build.yaml
, running automatically 3 times a week:
# Name of workflow
name: Build README
# Run workflow at 12:01 on Sunday, Wednesday, and Friday
on:
schedule:
- cron: '1 12 * * 0,3,5'
# Run workflow on pushes to main branch
push:
branches:
- main
# Steps to carry out
jobs:
build:
# Create a ubuntu virtual machine
runs-on: ubuntu-latest
# Checkout repo code
steps:
- name: Checkout repo
uses: actions/checkout@v2
# Install node
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 10.16
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true
# Run script "updateReadme.js"
- name: Update README
run: |-
node updateReadme.js
cat README.md
# Commit changes
- name: Commit and push if changed
run: |-
git diff
git config --global user.email "readme-bot@example.com"
git config --global user.name "README-bot"
git add -A
git commit -m "Updated articles" || exit 0
git push
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.