Support more platforms and improve avatar handling

Added support for GitLab, Gitea, Forgejo, and custom/self-hosted Git services. Improved avatar logic to prioritize repository avatars, updated UI to reflect avatar source, simplified download URL generation, and enhanced localization and language support. Refactored code structure and updated styles for better appearance and responsiveness.
This commit is contained in:
feibisi 2025-07-31 17:49:25 +08:00
parent 959fc6b9b8
commit d04f2c7940
7 changed files with 1691 additions and 528 deletions

View file

@ -180,6 +180,17 @@
}
}, [owner, repo, platform, customDomain, customSiteName]);
// 获取显示用的头像 URL优先仓库头像
const getDisplayAvatarUrl = (repoData) => {
if (repoData.repo_avatar_url) {
return repoData.repo_avatar_url;
}
if (repoData.owner && repoData.owner.avatar_url) {
return repoData.owner.avatar_url;
}
return '';
};
const renderPreview = () => {
if (loading) {
return el('div', { className: 'git-embed-loading' },
@ -209,18 +220,11 @@
const avatarClass = `git-embed-avatar git-embed-avatar-${avatarSize}`;
const buttonClass = `git-embed-button-${buttonSize}`;
let downloadUrl = '';
if (repoData.archive_url) {
const defaultBranch = repoData.default_branch || 'main';
if (repoData.platform === 'github') {
downloadUrl = repoData.archive_url.replace('{archive_format}', 'zipball').replace('{/ref}', `/${defaultBranch}`);
} else {
downloadUrl = repoData.archive_url;
if (downloadUrl.includes('main.zip') && defaultBranch !== 'main') {
downloadUrl = downloadUrl.replace('main.zip', `${defaultBranch}.zip`);
}
}
}
// 使用简化的下载地址
const downloadUrl = repoData.archive_url || '';
// 获取显示头像
const displayAvatarUrl = getDisplayAvatarUrl(repoData);
return el('div', { className: cardClass },
showSiteInfo && repoData.site_info && el('div', {
@ -243,10 +247,11 @@
el('div', { className: 'git-embed-header' },
el('div', { className: 'git-embed-title-section' },
showAvatar && repoData.owner && el('img', {
src: repoData.owner.avatar_url,
alt: repoData.owner.login,
className: avatarClass
showAvatar && displayAvatarUrl && el('img', {
src: displayAvatarUrl,
alt: repoData.name,
className: avatarClass,
title: repoData.repo_avatar_url ? 'Repository Avatar' : 'Owner Avatar'
}),
el('div', { className: 'git-embed-title-content' },
el('h3', { className: 'git-embed-title' },
@ -264,7 +269,13 @@
target: '_blank',
rel: 'noopener',
className: 'git-embed-owner-link'
}, `@${repoData.owner.login}`)
}, `@${repoData.owner.login}`),
repoData.repo_avatar_url && el('span', {
className: 'git-embed-repo-avatar-badge',
title: 'Repository has custom avatar'
},
el('span', { className: 'dashicons dashicons-format-image' })
)
)
)
),
@ -319,10 +330,10 @@
el('span', { className: 'dashicons dashicons-admin-page' }),
'Clone'
),
showDownloadButton && el('a', {
showDownloadButton && downloadUrl && el('a', {
href: downloadUrl,
className: `git-embed-button git-embed-button-secondary ${buttonClass}`,
download: `${repoData.name}.zip`
download: `${repoData.name}-${repoData.default_branch || 'main'}.zip`
},
el('span', { className: 'dashicons dashicons-download' }),
'Download ZIP'
@ -427,9 +438,10 @@
onChange: (value) => setAttributes({ showSiteInfo: value })
}),
el(ToggleControl, {
label: __('Show Owner Avatar', 'git-embed-feicode'),
label: __('Show Avatar', 'git-embed-feicode'),
checked: showAvatar,
onChange: (value) => setAttributes({ showAvatar: value })
onChange: (value) => setAttributes({ showAvatar: value }),
help: 'Shows repository avatar if available, otherwise owner avatar'
}),
showAvatar && el(SelectControl, {
label: __('Avatar Size', 'git-embed-feicode'),

View file

@ -179,21 +179,22 @@
border-radius: 15%;
flex-shrink: 0;
border: 2px solid #e1e4e8;
padding: 8px;
}
.git-embed-avatar-small {
width: 32px;
height: 32px;
width: 26px;
height: 26px;
}
.git-embed-avatar-medium {
width: 40px;
height: 40px;
width: 30px;
height: 30px;
}
.git-embed-avatar-large {
width: 48px;
height: 48px;
width: 35px;
height: 35px;
}
.git-embed-owner-info {
@ -287,6 +288,7 @@
.git-embed-description .dashicons {
margin-top: 2px;
flex-shrink: 0;
font-size: 18px;
}
.git-embed-stats {
@ -513,13 +515,13 @@ line-height: 1.25;
}
.git-embed-avatar-large {
width: 40px;
height: 40px;
width: 30px;
height: 30px;
}
.git-embed-avatar-medium {
width: 32px;
height: 32px;
width: 26px;
height: 26px;
}
.git-embed-owner-info {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,180 @@
{
"domain": "messages",
"locale_data": {
"messages": {
"": {
"domain": "messages",
"plural_forms": "nplurals=1; plural=0;",
"lang": "zh_CN"
},
"Git Repository": [
"Git 仓库"
],
"Embed a Git repository with information and stats": [
"嵌入包含信息和统计数据的 Git 仓库"
],
"Repository Settings": [
"仓库设置"
],
"Platform": [
"平台"
],
"Custom Domain": [
"自定义域名"
],
"Custom Site Name (Optional)": [
"自定义站点名称(可选)"
],
"Repository Owner": [
"仓库所有者"
],
"Repository Name": [
"仓库名称"
],
"Display Options": [
"显示选项"
],
"Show Site Information": [
"显示站点信息"
],
"Show Avatar": [
"显示头像"
],
"Avatar Size": [
"头像大小"
],
"Show Description": [
"显示描述"
],
"Show Programming Language": [
"显示编程语言"
],
"Show Statistics": [
"显示统计数据"
],
"Show Action Buttons": [
"显示操作按钮"
],
"Button Options": [
"按钮选项"
],
"Show View Repository Button": [
"显示查看仓库按钮"
],
"Show Clone Button": [
"显示克隆按钮"
],
"Show Download ZIP Button": [
"显示下载 ZIP 按钮"
],
"Show Issues Button": [
"显示议题按钮"
],
"Show Forks Button": [
"显示分叉按钮"
],
"Button Style": [
"按钮样式"
],
"Button Size": [
"按钮大小"
],
"Style Options": [
"样式选项"
],
"Card Style": [
"卡片样式"
],
"Please enter repository owner and name": [
"请输入仓库所有者和名称"
],
"Please enter custom domain for %s": [
"请输入 %s 的自定义域名"
],
"Fetching repository data...": [
"正在获取仓库数据..."
],
"Failed to fetch repository": [
"获取仓库失败"
],
"Network error occurred": [
"网络错误"
],
"Configure your repository details in the sidebar": [
"在侧边栏配置您的仓库详情"
],
"Fetch Repository": [
"获取仓库"
],
"Fetching...": [
"正在获取..."
],
"Self-hosted Git service requires custom domain": [
"自托管 Git 服务需要自定义域名"
],
"Enter the domain of your %s instance": [
"输入您的 %s 实例域名"
],
"Override the automatically detected site name": [
"覆盖自动检测的站点名称"
],
"Shows repository avatar if available, otherwise owner avatar": [
"如果可用,显示仓库头像,否则显示所有者头像"
],
"GitHub": [
"GitHub"
],
"Gitea": [
"Gitea"
],
"Forgejo": [
"Forgejo"
],
"GitLab (Self-hosted)": [
"GitLab自托管"
],
"Custom Git Service": [
"自定义 Git 服务"
],
"Small": [
"小"
],
"Medium": [
"中"
],
"Large": [
"大"
],
"Default": [
"默认"
],
"Primary (Green)": [
"主要(绿色)"
],
"Secondary (Gray)": [
"次要(灰色)"
],
"Outline": [
"轮廓"
],
"Ghost": [
"幽灵"
],
"Minimal": [
"简约"
],
"Bordered": [
"边框"
],
"Shadow": [
"阴影"
],
"Gradient": [
"渐变"
],
"Glassmorphism": [
"玻璃态"
]
}
}
}

Binary file not shown.

View file

@ -0,0 +1,298 @@
# Copyright (C) 2024 feiCode
# This file is distributed under the same license as the Git Embed for feiCode plugin.
# Translators:
# feiCode Team, 2024
msgid ""
msgstr ""
"Project-Id-Version: Git Embed for feiCode 1.0.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/git-embed-feicode\n"
"POT-Creation-Date: 2024-12-31 12:00+0000\n"
"PO-Revision-Date: 2025-07-31 17:43+0800\n"
"Last-Translator: feiCode Team\n"
"Language-Team: Chinese (China)\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.6\n"
#. Plugin Name of the plugin/theme
msgid "Git Embed for feiCode"
msgstr "Git 仓库嵌入"
#. Plugin Description of the plugin/theme
msgid "Embed Git repositories from GitHub/Gitlab/Gitea/Forgejo and Self-hosted Git service with beautiful card"
msgstr "使用精美卡片嵌入 Git 仓库"
#. Author of the plugin/theme
msgid "feiCode"
msgstr "菲码源库"
#: block.js:15
msgid "Git Repository"
msgstr "Git 仓库"
#: block.js:16
msgid "Embed a Git repository with information and stats"
msgstr "嵌入包含信息和统计数据的 Git 仓库"
#: block.js:170
msgid "Repository Settings"
msgstr "仓库设置"
#: block.js:174
msgid "Platform"
msgstr "平台"
#: block.js:185
msgid "Custom Domain"
msgstr "自定义域名"
#: block.js:195
msgid "Custom Site Name (Optional)"
msgstr "自定义站点名称(可选)"
#: block.js:205
msgid "Repository Owner"
msgstr "仓库所有者"
#: block.js:214
msgid "Repository Name"
msgstr "仓库名称"
#: block.js:227
msgid "Display Options"
msgstr "显示选项"
#: block.js:231
msgid "Show Site Information"
msgstr "显示站点信息"
#: block.js:235
msgid "Show Avatar"
msgstr "显示头像"
#: block.js:240
msgid "Avatar Size"
msgstr "头像大小"
#: block.js:252
msgid "Show Description"
msgstr "显示描述"
#: block.js:256
msgid "Show Programming Language"
msgstr "显示编程语言"
#: block.js:260
msgid "Show Statistics"
msgstr "显示统计数据"
#: block.js:264
msgid "Show Action Buttons"
msgstr "显示操作按钮"
#: block.js:269
msgid "Button Options"
msgstr "按钮选项"
#: block.js:273
msgid "Show View Repository Button"
msgstr "显示查看仓库按钮"
#: block.js:278
msgid "Show Clone Button"
msgstr "显示克隆按钮"
#: block.js:283
msgid "Show Download ZIP Button"
msgstr "显示下载 ZIP 按钮"
#: block.js:288
msgid "Show Issues Button"
msgstr "显示议题按钮"
#: block.js:293
msgid "Show Forks Button"
msgstr "显示分叉按钮"
#: block.js:298
msgid "Button Style"
msgstr "按钮样式"
#: block.js:312
msgid "Button Size"
msgstr "按钮大小"
#: block.js:326
msgid "Style Options"
msgstr "样式选项"
#: block.js:330
msgid "Card Style"
msgstr "卡片样式"
#: git-embed-feicode.php:85
msgid "Repository information required"
msgstr "需要仓库信息"
#: git-embed-feicode.php:89
msgid "Custom domain required for %s"
msgstr "%s 需要自定义域名"
#: git-embed-feicode.php:95
msgid "Failed to fetch repository data"
msgstr "获取仓库数据失败"
#: git-embed-feicode.php:672
msgid "Insufficient permissions"
msgstr "权限不足"
#: git-embed-feicode.php:684
msgid "Cache cleared successfully"
msgstr "缓存清理成功"
#. Error messages
msgid "Please enter repository owner and name"
msgstr "请输入仓库所有者和名称"
#, javascript-format
msgid "Please enter custom domain for %s"
msgstr "请输入 %s 的自定义域名"
msgid "Fetching repository data..."
msgstr "正在获取仓库数据..."
msgid "Failed to fetch repository"
msgstr "获取仓库失败"
msgid "Network error occurred"
msgstr "网络错误"
msgid "Configure your repository details in the sidebar"
msgstr "在侧边栏配置您的仓库详情"
msgid "Fetch Repository"
msgstr "获取仓库"
msgid "Fetching..."
msgstr "正在获取..."
#. Help texts
msgid "Self-hosted Git service requires custom domain"
msgstr "自托管 Git 服务需要自定义域名"
#, javascript-format
msgid "Enter the domain of your %s instance"
msgstr "输入您的 %s 实例域名"
msgid "Override the automatically detected site name"
msgstr "覆盖自动检测的站点名称"
msgid "Shows repository avatar if available, otherwise owner avatar"
msgstr "如果可用,显示仓库头像,否则显示所有者头像"
#. Button labels
msgid "View Repository"
msgstr "查看仓库"
msgid "Clone"
msgstr "克隆"
msgid "Download ZIP"
msgstr "下载 ZIP"
msgid "Issues"
msgstr "议题"
msgid "Forks"
msgstr "分叉"
msgid "Copied!"
msgstr "已复制!"
#. Stats labels
msgid "Stars:"
msgstr "星标:"
msgid "Forks:"
msgstr "分叉:"
msgid "Issues:"
msgstr "议题:"
#. Options
msgid "GitHub"
msgstr "GitHub"
msgid "Gitea"
msgstr "Gitea"
msgid "Forgejo"
msgstr "Forgejo"
msgid "GitLab (Self-hosted)"
msgstr "GitLab自托管"
msgid "Custom Git Service"
msgstr "自定义 Git 服务"
msgid "Small"
msgstr "小"
msgid "Medium"
msgstr "中"
msgid "Large"
msgstr "大"
msgid "Default"
msgstr "默认"
msgid "Primary (Green)"
msgstr "主要(绿色)"
msgid "Secondary (Gray)"
msgstr "次要(灰色)"
msgid "Outline"
msgstr "轮廓"
msgid "Ghost"
msgstr "幽灵"
msgid "Minimal"
msgstr "简约"
msgid "Bordered"
msgstr "边框"
msgid "Shadow"
msgstr "阴影"
msgid "Gradient"
msgstr "渐变"
msgid "Glassmorphism"
msgstr "玻璃态"
#. Tooltips and titles
msgid "Click to copy clone URL"
msgstr "点击复制克隆链接"
msgid "Repository Avatar"
msgstr "仓库头像"
msgid "Owner Avatar"
msgstr "所有者头像"
msgid "Repository has custom avatar"
msgstr "仓库有自定义头像"
#. Owner types
msgid "Organization"
msgstr "组织"
msgid "User"
msgstr "用户"

View file

@ -0,0 +1,296 @@
# Copyright (C) 2024 feiCode
# This file is distributed under the same license as the Git Embed for feiCode plugin.
msgid ""
msgstr ""
"Project-Id-Version: Git Embed for feiCode 1.0.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/git-embed-feicode\n"
"POT-Creation-Date: 2024-12-31 12:00+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: WordPress POT Generator\n"
#. Plugin Name of the plugin/theme
msgid "Git Embed for feiCode"
msgstr ""
#. Plugin Description of the plugin/theme
msgid "Embed Git repositories from GitHub/Gitlab/Gitea/Forgejo and Self-hosted Git service with beautiful cards
"
msgstr ""
#. Author of the plugin/theme
msgid "feiCode"
msgstr ""
#: block.js:15
msgid "Git Repository"
msgstr ""
#: block.js:16
msgid "Embed a Git repository with information and stats"
msgstr ""
#: block.js:170
msgid "Repository Settings"
msgstr ""
#: block.js:174
msgid "Platform"
msgstr ""
#: block.js:185
msgid "Custom Domain"
msgstr ""
#: block.js:195
msgid "Custom Site Name (Optional)"
msgstr ""
#: block.js:205
msgid "Repository Owner"
msgstr ""
#: block.js:214
msgid "Repository Name"
msgstr ""
#: block.js:227
msgid "Display Options"
msgstr ""
#: block.js:231
msgid "Show Site Information"
msgstr ""
#: block.js:235
msgid "Show Avatar"
msgstr ""
#: block.js:240
msgid "Avatar Size"
msgstr ""
#: block.js:252
msgid "Show Description"
msgstr ""
#: block.js:256
msgid "Show Programming Language"
msgstr ""
#: block.js:260
msgid "Show Statistics"
msgstr ""
#: block.js:264
msgid "Show Action Buttons"
msgstr ""
#: block.js:269
msgid "Button Options"
msgstr ""
#: block.js:273
msgid "Show View Repository Button"
msgstr ""
#: block.js:278
msgid "Show Clone Button"
msgstr ""
#: block.js:283
msgid "Show Download ZIP Button"
msgstr ""
#: block.js:288
msgid "Show Issues Button"
msgstr ""
#: block.js:293
msgid "Show Forks Button"
msgstr ""
#: block.js:298
msgid "Button Style"
msgstr ""
#: block.js:312
msgid "Button Size"
msgstr ""
#: block.js:326
msgid "Style Options"
msgstr ""
#: block.js:330
msgid "Card Style"
msgstr ""
#: git-embed-feicode.php:85
msgid "Repository information required"
msgstr ""
#: git-embed-feicode.php:89
msgid "Custom domain required for %s"
msgstr ""
#: git-embed-feicode.php:95
msgid "Failed to fetch repository data"
msgstr ""
#: git-embed-feicode.php:672
msgid "Insufficient permissions"
msgstr ""
#: git-embed-feicode.php:684
msgid "Cache cleared successfully"
msgstr ""
#. Error messages
msgid "Please enter repository owner and name"
msgstr ""
#, javascript-format
msgid "Please enter custom domain for %s"
msgstr ""
msgid "Fetching repository data..."
msgstr ""
msgid "Failed to fetch repository"
msgstr ""
msgid "Network error occurred"
msgstr ""
msgid "Configure your repository details in the sidebar"
msgstr ""
msgid "Fetch Repository"
msgstr ""
msgid "Fetching..."
msgstr ""
#. Help texts
msgid "Self-hosted Git service requires custom domain"
msgstr ""
#, javascript-format
msgid "Enter the domain of your %s instance"
msgstr ""
msgid "Override the automatically detected site name"
msgstr ""
msgid "Shows repository avatar if available, otherwise owner avatar"
msgstr ""
#. Button labels
msgid "View Repository"
msgstr ""
msgid "Clone"
msgstr ""
msgid "Download ZIP"
msgstr ""
msgid "Issues"
msgstr ""
msgid "Forks"
msgstr ""
msgid "Copied!"
msgstr ""
#. Stats labels
msgid "Stars:"
msgstr ""
msgid "Forks:"
msgstr ""
msgid "Issues:"
msgstr ""
#. Options
msgid "GitHub"
msgstr ""
msgid "Gitea"
msgstr ""
msgid "Forgejo"
msgstr ""
msgid "GitLab (Self-hosted)"
msgstr ""
msgid "Custom Git Service"
msgstr ""
msgid "Small"
msgstr ""
msgid "Medium"
msgstr ""
msgid "Large"
msgstr ""
msgid "Default"
msgstr ""
msgid "Primary (Green)"
msgstr ""
msgid "Secondary (Gray)"
msgstr ""
msgid "Outline"
msgstr ""
msgid "Ghost"
msgstr ""
msgid "Minimal"
msgstr ""
msgid "Bordered"
msgstr ""
msgid "Shadow"
msgstr ""
msgid "Gradient"
msgstr ""
msgid "Glassmorphism"
msgstr ""
#. Tooltips and titles
msgid "Click to copy clone URL"
msgstr ""
msgid "Repository Avatar"
msgstr ""
msgid "Owner Avatar"
msgstr ""
msgid "Repository has custom avatar"
msgstr ""
#. Owner types
msgid "Organization"
msgstr ""
msgid "User"
msgstr ""