Skip to content

Commit c4c86fc

Browse files
authored
feat(sites/tangled): support commit diff filetree (#206)
1 parent b949a16 commit c4c86fc

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/sites/tangled.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ReplacementSelectorSet, Site } from '.';
2+
import { ATTRIBUTE_PREFIX } from '../constants';
23

34
const mainRepositoryImplementation: ReplacementSelectorSet = {
45
row: '#file-tree > div, .tree > div',
@@ -10,7 +11,30 @@ const mainRepositoryImplementation: ReplacementSelectorSet = {
1011
isCollapsable: (_rowEl, _fileNameEl, _iconEl) => false,
1112
};
1213

14+
const commitTreeImplementation: ReplacementSelectorSet = {
15+
row: '.diff-stat .tree-directory, .diff-stat .tree-file',
16+
filename: '.filename',
17+
icon: 'svg',
18+
isDirectory: (rowEl, _fileNameEl, _iconEl) =>
19+
rowEl.classList.contains('tree-directory'),
20+
isSubmodule: (_rowEl, _fileNameEl, _iconEl) => false, // TODO: Implement isSubmodule.
21+
isCollapsable: (rowEl, fileNameEl, iconEl) =>
22+
commitTreeImplementation.isDirectory(rowEl, fileNameEl, iconEl),
23+
};
24+
commitTreeImplementation.styles = /* css */ `
25+
/* Hide directory icons by default. */
26+
${commitTreeImplementation.row.split(',').at(0)} ${commitTreeImplementation.icon} {
27+
display: none;
28+
}
29+
30+
/* Show relevant extension directory icon depending on open/closed state. */
31+
details[open] > summary > .tree-directory svg[${ATTRIBUTE_PREFIX}-iconname$='_open'],
32+
details:not([open]) > summary > .tree-directory svg[${ATTRIBUTE_PREFIX}]:not([${ATTRIBUTE_PREFIX}-iconname$='_open']) {
33+
display: inline-block !important;
34+
}
35+
`.trim();
36+
1337
export const tangled: Site = {
1438
domains: ['tangled.sh'],
15-
replacements: [mainRepositoryImplementation],
39+
replacements: [mainRepositoryImplementation, commitTreeImplementation],
1640
};

0 commit comments

Comments
 (0)