Skip to content

Commit e6be108

Browse files
WitnessMeeRuben De Voogdt
andauthored
feat: add support for forgejo (#132)
* feat(forgejo): add Forgejo provider (codeberg.org + self-host) * feat(forgejo): undo formatting Signed-off-by: WitnessMee <[email protected]> --------- Signed-off-by: WitnessMee <[email protected]> Co-authored-by: Ruben De Voogdt <[email protected]>
1 parent 84754a1 commit e6be108

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/manifests/base.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"*://gitea.com/*",
2020
"*://gitlab.com/*",
2121
"*://gitee.com/*",
22-
"*://sourceforge.net/*"
22+
"*://sourceforge.net/*",
23+
"*://codeberg.org/*"
2324
],
2425
"js": [
2526
"./main.js"
@@ -54,6 +55,7 @@
5455
"*://gitlab.com/*",
5556
"*://gitee.com/*",
5657
"*://sourceforge.net/*",
58+
"*://codeberg.org/*",
5759
"*://*/*"
5860
]
5961
}

src/providers/forgejo.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Provider } from '../models';
2+
3+
export default function forgejo(): Provider {
4+
return {
5+
name: 'forgejo',
6+
domains: [
7+
{
8+
host: 'codeberg.org',
9+
test: /^codeberg\.org$/,
10+
},
11+
],
12+
selectors: {
13+
// Primary Forgejo structure + a fallback for older Gitea-like markup
14+
row: '#repo-files-table .entry, #repo-files-table .repo-file-item',
15+
filename: '.name a, .repo-file-cell.name a',
16+
icon: '.name svg, .repo-file-cell.name svg',
17+
// Element by which to detect if the tested domain is forgejs.
18+
detect: 'body > .full.height > .page-content[role=main]',
19+
},
20+
canSelfHost: true,
21+
isCustom: false,
22+
getIsLightTheme: () => false,
23+
getIsDirectory: ({ icon }) =>
24+
icon.classList.contains('octicon-file-directory-fill'),
25+
getIsSubmodule: ({ icon }) =>
26+
icon.classList.contains('octicon-file-submodule'),
27+
getIsSymlink: ({ icon }) =>
28+
icon.classList.contains('octicon-file-symlink-file'),
29+
replaceIcon: (svgEl, newSVG) => {
30+
svgEl
31+
.getAttributeNames()
32+
.forEach(
33+
(attr) =>
34+
attr !== 'src' &&
35+
!/^data-material-icons-extension/.test(attr) &&
36+
newSVG.setAttribute(attr, svgEl.getAttribute(attr) ?? '')
37+
);
38+
39+
svgEl.parentNode?.replaceChild(newSVG, svgEl);
40+
},
41+
onAdd: () => {},
42+
transformFileName: (
43+
rowEl: HTMLElement,
44+
_iconEl: HTMLElement,
45+
fileName: string
46+
): string => {
47+
// try to match the 'Source code (zip)' type of rows in releases page in github.
48+
if (
49+
rowEl.querySelector('.archive-link') &&
50+
fileName.includes('Source code')
51+
) {
52+
return fileName.replace(/\s+\((.*?)\)$/, '.$1');
53+
}
54+
55+
return fileName;
56+
},
57+
};
58+
}

src/providers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getCustomProviders } from '../lib/custom-providers';
22
import { Provider } from '../models';
33
import azure from './azure';
44
import bitbucket from './bitbucket';
5+
import forgejo from './forgejo';
56
import gitea from './gitea';
67
import gitee from './gitee';
78
import github from './github';
@@ -16,6 +17,7 @@ export const providers: Record<string, () => Provider> = {
1617
github,
1718
gitlab,
1819
sourceforge,
20+
forgejo,
1921
};
2022

2123
export const providerConfig: Record<string, Provider> = {};

0 commit comments

Comments
 (0)