Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gogf/gf-site
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Oct 29, 2024
2 parents f10380d + eda2eb6 commit 2591c35
Show file tree
Hide file tree
Showing 27 changed files with 3,676 additions and 510 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci
- name: generate contributors
run: bash .github/workflows/generate-contributors.sh
- name: Build website
run: npm run build
- name: Deploy to GitHub Pages
Expand Down
141 changes: 141 additions & 0 deletions .github/workflows/generate-contributors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
const fs = require("fs")
const sharp = require('sharp')

// github api url
const githubUrl = `https://api.github.com/repos/gogf/gf/contributors`

// 生成 svg 的位置
const svgPath = "../../static/img/contributors.svg"
// 单个头像的质量, 1 - 100
const quality = 10

// 单个头像的宽高
const width = 64, height = 64
// 头像之间的间距
const xSpace = 4, ySpace = 4
// 每一行的头像数量
const row = 20

getContributors().then(contributors => {
genSvg(contributors).then(r => {
console.log(`${svgPath} 生成成功, 一共 ${contributors.length} 个贡献者`)
})
}).catch(error => {
console.error(error)
})

// getContributors 获取所有的贡献者
async function getContributors() {
const contributors = []
let page = 1
let per_page = 100
let hasMore = true

while (hasMore) {
const response = await fetch(`${githubUrl}?page=${page}&per_page=${per_page}`)
const data = await response.json()

if (response.status !== 200) {
throw new Error(`Failed to fetch contributors: ${response.statusText}`)
}

contributors.push(...data)

if (data.length < per_page) {
hasMore = false
} else {
page++
}
}

return contributors
}

// genSvg 生成 svg 文件
async function genSvg(data) {
let contributorsArr = chunkArray(data, row)

// 计算整个 svg 的宽高
let svgWidth = (width + xSpace) * row + xSpace
let svgHeight = (height + ySpace) * contributorsArr.length + ySpace

// 创建 svg 内容
let svgContent = `
<svg xmlns="http://www.w3.org/2000/svg" width="${svgWidth}" height="${svgHeight}">
<style> .gf-svg { cursor:pointer } </style>
`

// x 表示头像的 x 坐标,y 表示头像的 y 坐标
// 初始从左上角开始
let x = xSpace, y = ySpace
let n = 0
for (const contributors of contributorsArr) {
for (const contributor of contributors) {
svgContent += await generateAvatar(contributor, x, y)
console.log(`生成第 ${++n} 个贡献者: ${contributor.login}`)
x += width + xSpace
}

// 换行
x = xSpace
y += height + ySpace
}

svgContent += `</svg>`

// 保存 svg 文件
fs.writeFileSync(svgPath, svgContent)
}

// chunkArray 函数用于将数组拆分为指定大小的块
function chunkArray(array, chunkSize) {
const result = []
for (let i = 0; i < array.length; i += chunkSize) {
result.push(array.slice(i, i + chunkSize))
}
return result
}

// generateAvatar 生成一个base64格式的头像的 svg 代码
//
// <defs xmlns="http://www.w3.org/2000/svg">
// <clipPath id="clip-oldme-git">
// <circle cx="273" cy="17" r="15"/>
// </clipPath>
// </defs>
// <a xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="gf-svg" target="_blank" rel="nofollow" xlink:href="https://github.com/oldme-git" id="oldme-git">
// <image x="258" y="2" width="30" height="30" xlink:href="data:image/png;base64,..." clip-path="url(#clip-oldme-git)/>
// </a>
async function generateAvatar(contributor, x, y) {
const base64Image = await convertImageToBase64(contributor.avatar_url)
const clipPathId = `clip-${contributor.login}`

return `
<defs>
<clipPath id="${clipPathId}">
<circle cx="${x + width / 2}" cy="${y + height / 2}" r="${width / 2}" />
</clipPath>
</defs>
<a
class="gf-svg" target="_blank" rel="nofollow"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="${contributor.html_url}"
id="${contributor.login}">
<image x="${x}" y="${y}" width="${width}" height="${height}" xlink:href="${base64Image}" clip-path="url(#${clipPathId})"/>
</a>
`
}

// convertImageToBase64 将 url 中的图片转换为 base64 格式
async function convertImageToBase64(url) {
const response = await fetch(url)
const buffer = await response.arrayBuffer()

const compressedBuffer = await sharp(Buffer.from(buffer))
.toFormat("jpeg", { quality })
.toBuffer()
const base64Image = compressedBuffer.toString("base64")

return `data:image/jpeg;base64,${base64Image}`
}
5 changes: 5 additions & 0 deletions .github/workflows/generate-contributors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd .github/workflows
node generate-contributors.js
cd -
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ https://docusaurus.io/zh-CN/docs/markdown-features/code-blocks
- 【WEB开发】等等
- 【版本发布】
- 【技术交流】
- 【交流群】
- 【框架设计】
- 【常用资料】
- 【使用案例】
- 【支持我们】
-捐赠
-来杯咖啡
- 【加入我们】
File renamed without changes
4 changes: 2 additions & 2 deletions help/index.md → communication/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: '获得帮助'
sidebar_position: 1
title: '交流群'
sidebar_position: 0
---

## 加入QQ群
Expand Down
12 changes: 12 additions & 0 deletions communication/技术分享交流/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: '技术分享交流'
sidebar_position: 1
---

- [2021-03-12 初次见面](/communication/技术分享交流/0-2021-03-12%20初次见面)
- [2021-04-17 GoCN Gopher Meetup](/communication/技术分享交流/1-2021-04-17%20GoCN%20Gopher%20Meetup)
- [2021-06-24 GoFrame ORM 组件设计](/communication/技术分享交流/2-2021-06-24%20GoFrame%20ORM组件设计)
- [2022-01-27 Let's GoFrame](/communication/技术分享交流/3-2022-01-27%20Let's%20GoFrame)
- [2022-05-17 GoFrame 贡献指南&使用答疑](/communication/技术分享交流/4-2022-05-17%20GoFrame贡献指南&使用答疑)
- [2022-06-22 GoFrame v2.1 功能特性&使用答疑](/communication/技术分享交流/5-2022-06-22%20GoFrame%20v2.1功能特性&使用答疑)
- [2022-09-14 ORM 驱动开发](/communication/技术分享交流/6-2022-09-14%20ORM驱动开发)
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: '开发手册'
sidebar_position: 0
---
57 changes: 29 additions & 28 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { themes as prismThemes } from 'prism-react-renderer';
// https://docusaurus.io/docs/3.2.1/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter
// https://docusaurus.io/docs/3.2.1/api/docusaurus-config
const config: Config = {
title: 'GoFrame官网 - 类似PHP-Laravel, Java-SpringBoot的Go企业级开发框架',
title: 'GoFrame官网 - 类似PHP-Laravel和Java-SpringBoot的Go企业级开发框架',
tagline:
'GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.',
favicon: '/img/favicon.ico',
url: 'https://goframe.org/',
baseUrl: '/',
baseUrl: '/gf-site/',
trailingSlash: false,
organizationName: 'gogf',
projectName: 'gf',
Expand Down Expand Up @@ -73,7 +73,11 @@ const config: Config = {
path: 'quick',
routeBasePath: 'quick',
sidebarPath: require.resolve('./sidebars.ts'),
// ... other options
// 编辑当前页面的配置
editUrl: 'https://github.com/gogf/gf-site/blob/main/',
// 显示更新时间和作者
showLastUpdateTime: true,
showLastUpdateAuthor: true,
},
],
// 版本发布
Expand All @@ -84,17 +88,26 @@ const config: Config = {
path: 'release',
routeBasePath: 'release',
sidebarPath: require.resolve('./sidebars.ts'),
// ... other options
// 编辑当前页面的配置
editUrl: 'https://github.com/gogf/gf-site/blob/main/',
// 显示更新时间和作者
showLastUpdateTime: true,
showLastUpdateAuthor: true,
},
],
// 获得帮助
// 技术交流
[
'@docusaurus/plugin-content-docs',
{
id: 'help',
path: 'help',
routeBasePath: 'help',
id: 'communication',
path: 'communication',
routeBasePath: 'communication',
sidebarPath: require.resolve('./sidebars.ts'),
// 编辑当前页面的配置
editUrl: 'https://github.com/gogf/gf-site/blob/main/',
// 显示更新时间和作者
showLastUpdateTime: true,
showLastUpdateAuthor: true,
},
],
// 支持我们
Expand All @@ -105,22 +118,17 @@ const config: Config = {
path: 'supportus',
routeBasePath: 'supportus',
sidebarPath: require.resolve('./sidebars.ts'),
},
],
// 加入我们
[
'@docusaurus/plugin-content-docs',
{
id: 'joinus',
path: 'joinus',
routeBasePath: 'joinus',
sidebarPath: require.resolve('./sidebars.ts'),
// 编辑当前页面的配置
editUrl: 'https://github.com/gogf/gf-site/blob/main/',
// 显示更新时间和作者
showLastUpdateTime: true,
showLastUpdateAuthor: true,
},
],
],
themeConfig: {
colorMode: {
defaultMode: "light",
defaultMode: 'light',
disableSwitch: true,
respectPrefersColorScheme: false,
},
Expand Down Expand Up @@ -179,9 +187,9 @@ const config: Config = {
{
type: 'docSidebar',
sidebarId: 'tutorialSidebar',
docsPluginId: 'help',
docsPluginId: 'communication',
position: 'right',
label: '获得帮助',
label: '技术交流',
},
{
type: 'docSidebar',
Expand All @@ -190,13 +198,6 @@ const config: Config = {
position: 'right',
label: '支持我们',
},
{
type: 'docSidebar',
sidebarId: 'tutorialSidebar',
docsPluginId: 'joinus',
position: 'right',
label: '加入我们',
},
{
type: 'docsVersionDropdown',
position: 'right',
Expand Down
Loading

0 comments on commit 2591c35

Please sign in to comment.