|
| 1 | +<!-- markdownlint-disable-file MD033 MD041 --> |
| 2 | +<h1 align="center">GitHub Projects Embed | FixIt</h1> |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +<div align="center" class="ignore"> |
| 7 | + <p>Display your GitHub projects in the FixIt theme and generate blog posts from README.</p> |
| 8 | + <a href="/README.md">简体中文</a> | |
| 9 | + <a href="https://fixit.lruihao.cn/zh-cn/ecosystem/hugo-fixit/component-projects/?lang=chinese_traditional">繁體中文</a> | |
| 10 | + English | |
| 11 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=french">Français</a> | |
| 12 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=russian">Русский язык</a> | |
| 13 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=spanish">Español</a> | |
| 14 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=hindi">हिन्दी</a> | |
| 15 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=german">deutsch</a> | |
| 16 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=korean">한국어</a> | |
| 17 | + <a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/component-projects/?lang=japanese">しろうと</a> |
| 18 | +</div> |
| 19 | + |
| 20 | +## Demo |
| 21 | + |
| 22 | +- [Ecosystem | FixIt](https://fixit.lruihao.cn/ecosystem/) |
| 23 | +- [Lruihao's Projects](https://lruihao.cn/projects/) |
| 24 | + |
| 25 | +## Features |
| 26 | + |
| 27 | +- Support GitHub project cards display (`layout` or `shortcodes`) |
| 28 | +- Support generating blog posts from README (`content adapter`) |
| 29 | + |
| 30 | +## Requirements |
| 31 | + |
| 32 | +- [FixIt](https://github.com/hugo-fixit) v0.3.7 or higher |
| 33 | + |
| 34 | +## Installation |
| 35 | + |
| 36 | +The installation method is the same as [installing a theme](https://fixit.lruihao.cn/documentation/installation/). There are several ways to install, choose one. |
| 37 | + |
| 38 | +### Install as Hugo Module |
| 39 | + |
| 40 | +First make sure that your project itself is a [Hugo module](https://gohugo.io/hugo-modules/use-modules/#initialize-a-new-module). |
| 41 | + |
| 42 | +Then add this theme component to your `hugo.toml` configuration file: |
| 43 | + |
| 44 | +```toml |
| 45 | +[module] |
| 46 | + [[module.imports]] |
| 47 | + path = "github.com/hugo-fixit/FixIt" |
| 48 | + [[module.imports]] |
| 49 | + path = "github.com/hugo-fixit/component-projects" |
| 50 | +``` |
| 51 | + |
| 52 | +On the first start of Hugo it will download the required files. |
| 53 | + |
| 54 | +To update to the latest version of the module run: |
| 55 | + |
| 56 | +```bash |
| 57 | +hugo mod get -u |
| 58 | +hugo mod tidy |
| 59 | +``` |
| 60 | + |
| 61 | +### Install as Git Submodule |
| 62 | + |
| 63 | +Clone [FixIt](https://github.com/hugo-fixit) and this git repository into your theme folder and add it as submodules of your website directory. |
| 64 | + |
| 65 | +```bash |
| 66 | +git submodule add https://github.com/hugo-fixit/FixIt.git themes/FixIt |
| 67 | +git submodule add https://github.com/hugo-fixit/component-projects.git themes/component-projects |
| 68 | +``` |
| 69 | + |
| 70 | +Next edit `hugo.toml` of your project and add this theme component to your themes: |
| 71 | + |
| 72 | +```toml |
| 73 | +theme = ["FixIt", "component-projects"] |
| 74 | +``` |
| 75 | + |
| 76 | +## Inject Partial |
| 77 | + |
| 78 | +Finally, inject the theme component's assets in `layouts/partials/custom.html` within the `custom-head` or `custom-assets` block: |
| 79 | + |
| 80 | +```go-html-template |
| 81 | +{{- define "custom-assets" -}} |
| 82 | + {{- partial "inject/component-projects.html" . -}} |
| 83 | +{{- end -}} |
| 84 | +``` |
| 85 | + |
| 86 | +## Configuration (Optional) |
| 87 | + |
| 88 | +Obtaining repositories information relies on GitHub official API. Before starting to use it, it is recommended to generate personal access token on GitHub to prevent GitHub API usage limit. |
| 89 | + |
| 90 | +1. Click to jump to GitHub [Generate token](https://github.com/settings/tokens/new), select the scope named `public_repo` to generate personal access token. |
| 91 | +2. Configure with environment variable `HUGO_PARAMS_GHTOKEN=your-person-access-token`, see details in [os.Getenv | Hugo](https://gohugo.io/functions/os/getenv/#examples) |
| 92 | + |
| 93 | +## Usage |
| 94 | + |
| 95 | +### Layout |
| 96 | + |
| 97 | +First, create the `projects.yml` file and edit your data: |
| 98 | + |
| 99 | +```bash |
| 100 | +cp themes/component-projects/projects.yml.example data/projects.yml |
| 101 | +``` |
| 102 | + |
| 103 | +> If your site is multilingual, you can create a `projects.en.yml` file for English and `projects.zh-cn.yml` for Chinese. |
| 104 | +
|
| 105 | +Next, create a new page with the `projects` layout: |
| 106 | + |
| 107 | +```bash |
| 108 | +hugo new projects/_index.md |
| 109 | +``` |
| 110 | + |
| 111 | +Edit the front matter and content of the new page: |
| 112 | + |
| 113 | +```yaml |
| 114 | +--- |
| 115 | +title: My Projects |
| 116 | +titleIcon: fa-solid fa-laptop-code |
| 117 | +subtitle: <https://github.com/Lruihao> |
| 118 | +sectionSlot: Some text to display in the section slot which is above the related articles list. |
| 119 | +layout: projects |
| 120 | +--- |
| 121 | + |
| 122 | +Some text to display at the start of the page. |
| 123 | +``` |
| 124 | + |
| 125 | +### Shortcodes |
| 126 | + |
| 127 | +Use the `gh-repo-card-container` and `gh-repo-card` shortcodes in any page to display a GitHub repository card: |
| 128 | + |
| 129 | +```markdown |
| 130 | +{{< gh-repo-card-container >}} |
| 131 | + {{< gh-repo-card repo="hugo-fixit/component-projects" >}} |
| 132 | + {{< gh-repo-card repo="Lruihao/hugo-blog" >}} |
| 133 | +{{< /gh-repo-card-container >}} |
| 134 | +``` |
| 135 | + |
| 136 | +### Content Adapter |
| 137 | + |
| 138 | +:tada: This is a awesome feature! It can generate blog posts from the README of the repositories according to the projects data you configured. |
| 139 | + |
| 140 | +Create `_content.gotmpl` in projects section folder, add the following code: |
| 141 | + |
| 142 | +```go-html-template |
| 143 | +{{- partial "adapters/projects.html" . -}} |
| 144 | +``` |
| 145 | + |
| 146 | +Directory structure: |
| 147 | + |
| 148 | +```plain |
| 149 | +content/ |
| 150 | +├── projects/ |
| 151 | +│ ├── _content.gotmpl <-- content adapter |
| 152 | +│ └── _index.md <-- layout: projects |
| 153 | +data/ |
| 154 | +└── projects.yml <-- projects data |
| 155 | +``` |
| 156 | + |
| 157 | +Then, open the `hugo.toml` file and configure the `projectsAdapters` option to enable the content adapter: |
| 158 | + |
| 159 | +```toml |
| 160 | +[params] |
| 161 | + [params.projectsAdapters] |
| 162 | + enable = true |
| 163 | + onlyPublic = true |
| 164 | + categories = [] |
| 165 | + collections = [] |
| 166 | + ignoreList = [] |
| 167 | + [params.projectsAdapters.params] |
| 168 | + hiddenFromHomePage = true |
| 169 | + # more font matter here ... |
| 170 | +``` |
| 171 | + |
| 172 | +### Custom Blocks |
| 173 | + |
| 174 | +You can implement these blocks through `define`. |
| 175 | + |
| 176 | +| Block Name | Description | |
| 177 | +| :---------------- | :------------------------------------------------ | |
| 178 | +| `projects-aside` | Displayed in the aside of the projects page | |
| 179 | +| `projects-meta` | Displayed in the post meta of the projects page | |
| 180 | +| `projects-footer` | Displayed in the post footer of the projects page | |
| 181 | + |
| 182 | +## Scheduled tasks |
| 183 | + |
| 184 | +Since it uses server-side rendering, all data is fetched at build time and not requested from the GitHub API on each visit. Therefore, we can use scheduled tasks to update the data to keep it up to date. |
| 185 | + |
| 186 | +### Deploy to GitHub Pages |
| 187 | + |
| 188 | +If your site is hosted on GitHub Pages, you can use GitHub Actions to deploy automatically. |
| 189 | + |
| 190 | +```yaml |
| 191 | +name: Hugo build and deploy |
| 192 | +on: |
| 193 | + schedule: |
| 194 | + # Rebuid the site every day at 00:00 UTC to update the projects data |
| 195 | + - cron: '0 0 * * *' |
| 196 | + push: |
| 197 | + branches: [ main ] |
| 198 | + workflow_dispatch: |
| 199 | +jobs: |
| 200 | + # Your build and deploy jobs here |
| 201 | +``` |
| 202 | + |
| 203 | +### Deplot to Vercel |
| 204 | + |
| 205 | +If your site is hosted on Vercel, you can use Vercel's [Deploy Hooks](https://vercel.com/docs/deployments/deploy-hooks#creating-&-triggering-deploy-hooks) feature with GitHub Actions to deploy automatically. |
| 206 | + |
| 207 | +```yaml |
| 208 | +name: Vercel deploy hook |
| 209 | +on: |
| 210 | + schedule: |
| 211 | + # Rebuid the site every day at 00:00 UTC to update the projects data |
| 212 | + - cron: '0 0 * * *' |
| 213 | +jobs: |
| 214 | + Vercel-Deploy: |
| 215 | + runs-on: ubuntu-latest |
| 216 | + steps: |
| 217 | + - name: Trigger Vercel deploy hook |
| 218 | + run: | |
| 219 | + curl -X POST ${{ secrets.VERCEL_DEPLOY_HOOK }} |
| 220 | +``` |
| 221 | +
|
| 222 | +Create a deploy hook in the project settings of Vercel and add the `VERCEL_DEPLOY_HOOK` variable in the Secrets of the GitHub project. |
| 223 | + |
| 224 | +## Troubleshooting |
| 225 | + |
| 226 | +You can add the `--ignoreCache` parameter to the `hugo server` command to clear the cache in local server. |
0 commit comments