将你的 dev.to 文章更新到你的 Github 个人资料中

2025-06-09

将你的 dev.to 文章更新到你的 Github 个人资料中

在本文中,我将与您分享如何将您在 dev.to 上的最新文章更新到您的 Github 个人资料中。
图片描述

Github 个人资料

如果以下所有情况都成立,GitHub 将在您的个人资料页面上显示您的个人资料 README。

  • 您已创建一个名称与您的 GitHub 用户名匹配的存储库。
  • 该存储库是公开的。
  • 该存储库的根目录中包含一个名为 README.md 的文件。
  • README.md 文件包含任何内容。

如何将文章更新到存储库

按照我上一篇文章《创建动态 README.md 文件》中概述的相同方法,我最近开发了另一个 GitHub Action,用于更新dev.toGitHub 个人资料上的文章。

为此,请遵循以下简单的步骤:

步骤 1:在您的存储库中,创建一个名为 的文件README.md.template

第 2 步:在文件中写入您想要的任何内容README.md.template

步骤 3:在您的 中嵌入以下实体之一README.md.template

  • 文章列表:
{{ template "article-list" .Articles }}
Enter fullscreen mode Exit fullscreen mode

图片描述

  • 文章表:
{{ template "article-table" .Articles }}
Enter fullscreen mode Exit fullscreen mode

图片描述

如果您熟悉 Go 模板,您可以访问该root变量,其中包括以下字段:

  • Articles:Article 数组。您可以在model/article.go中查看 Article 结构体定义。
  • Time: 更新时间

步骤4:注册Github Action

  • 在您的存储库中创建一个文件.github/workflows/update-articles.yml
name: "Cronjob"
on:
 schedule:
  - cron: '15 0 * * *'

jobs:
    update-articles:
        permissions: write-all
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - name: Generate README
              uses: huantt/article-listing@v1.1.0
              with:
                username: YOUR_USERNAME_ON_DEV_TO                
                template-file: 'README.md.template'
                out-file: 'README.md'
                limit: 5
            - name: Commit
              run: |
                git config user.name github-actions
                git config user.email github-actions@github.com
                git add .
                git commit -m "update articles"
                git push origin main
Enter fullscreen mode Exit fullscreen mode

步骤 5:提交您的更改,然后 Github 操作将按照您指定的 cron 运行,以将文章更新到您的 README.md 文件中

源代码

请参阅此处的源代码和示例:https://github.com/huantt/article-listing

参考

鏂囩珷鏉ユ簮锛�https://dev.to/jacktt/update-your-devto-articles-into-your-github-profile-4dpi
PREV
在微服务中使用 Spring Boot 和 ActiveMQ 实现 Saga 模式
NEXT
使用 Node.js、AssemblyAI 和 StreamPot 构建你自己的 AI 视频编辑器