繁体   English   中英

我在从 codeforces 获取数据到我的 github 配置文件时遇到问题

[英]I have a problem fetching data from codeforces to my github profile

我在从 codeforces 获取数据到我的 github 配置文件时遇到问题 我无法将 js 代码添加到 readme.md 文件以从 codeforces 获取数据 当我尝试编写这样的 js 代码时,它显示为文本。

    <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>

您不会直接从配置文件README.md调用 javascript 程序。

但是你可以设置一个 GitHub 动作来更新所说的README.md ,这个动作可以调用任何东西。

例如,参见Dan Curtis的“ Self-updating GitHub Profile README with JavaScript ”。

GitHub 最近发布了一项功能,允许用户将 markdown 添加到他们的个人资料中。
人们做了一些很酷的事情,这激发了我创建一个 README 文件,它可以随着我的 Dev.to 帖子动态更新。
GitHub Actions 和 NodeJS 让这一切变得简单。
我创建了一个脚本来:

  • 获取我的 Dev.to 文章
  • 解析我的README
  • 用我最新的文章更新README

您需要 3 个文件:.github/workflows/build.yaml、updateReadme.js 和 README.md

.github/workflows/build.yaml的示例,每周自动运行 3 次:

# 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM