site: change doc support display contributor (#52409)

* save

* save

* save
pull/52407/head^2
thinkasany 1 week ago committed by GitHub
parent 35f8f89554
commit af63c666d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -20,6 +20,7 @@ interface ChangelogInfo {
version: string;
changelog: string;
refs: string[];
contributors: string[];
releaseDate: string;
}
@ -160,14 +161,30 @@ const ParseChangelog: React.FC<{ changelog: string }> = (props) => {
return <span>{parsedChangelog}</span>;
};
const RefLinks: React.FC<{ refs: string[] }> = ({ refs }) => {
const RefLinks: React.FC<{ refs: string[]; contributors: string[] }> = ({ refs, contributors }) => {
const { styles } = useStyle();
return (
<>
{refs?.map((ref) => (
<a className={styles.linkRef} key={ref} href={ref} target="_blank" rel="noreferrer">
#{ref.match(/[^/]+$/)?.[0]}
</a>
<React.Fragment key={ref}>
<a className={styles.linkRef} key={ref} href={ref} target="_blank" rel="noreferrer">
#{ref.match(/[^/]+$/)?.[0]}
</a>
</React.Fragment>
))}
{contributors?.map((contributor) => (
<React.Fragment key={contributor}>
<a
className={styles.linkRef}
key={contributor}
href={`https://github.com/${contributor}`}
target="_blank"
rel="noreferrer"
>
@{contributor}
</a>
</React.Fragment>
))}
</>
);
@ -178,7 +195,7 @@ const RenderChangelogList: React.FC<{ changelogList: ChangelogInfo[] }> = ({ cha
const { styles } = useStyle();
const len = changelogList.length;
for (let i = 0; i < len; i += 1) {
const { refs, changelog } = changelogList[i];
const { refs, changelog, contributors } = changelogList[i];
// Check if the next line is an image link and append it to the current line
if (i + 1 < len && changelogList[i + 1].changelog.trim().startsWith('<img')) {
const imgDom = new DOMParser().parseFromString(changelogList[i + 1].changelog, 'text/html');
@ -186,7 +203,7 @@ const RenderChangelogList: React.FC<{ changelogList: ChangelogInfo[] }> = ({ cha
elements.push(
<li key={i}>
<ParseChangelog changelog={changelog} />
<RefLinks refs={refs} />
<RefLinks refs={refs} contributors={contributors} />
<br />
<img
src={imgElement?.getAttribute('src') || ''}
@ -200,7 +217,7 @@ const RenderChangelogList: React.FC<{ changelogList: ChangelogInfo[] }> = ({ cha
elements.push(
<li key={i}>
<ParseChangelog changelog={changelog} />
<RefLinks refs={refs} />
<RefLinks refs={refs} contributors={contributors} />
</li>,
);
}

@ -101,7 +101,13 @@ const miscKeys = [
// Changelog map
const componentChangelog: Record<
string,
{ version: string; changelog: string; refs: string[]; releaseDate: string }[]
{
version: string;
changelog: string;
refs: string[];
releaseDate: string;
contributors: string[];
}[]
> = {};
Object.keys(componentNameMap).forEach((name) => {
componentChangelog[name] = [];
@ -127,6 +133,20 @@ const miscKeys = [
lastReleaseDate = matchReleaseDate[1];
}
// Get Contributor name
const contributors: string[] = [];
const usernameMatches = line.match(/\[@([^\]]+)\]/g);
if (usernameMatches) {
usernameMatches.forEach((match) => {
const usernameMatch = match.match(/\[@([^\]]+)\]/);
if (usernameMatch) {
const username = usernameMatch[1];
contributors.push(username);
}
});
}
// Start when get version
if (!lastVersion) {
continue;
@ -184,6 +204,7 @@ const miscKeys = [
changelog: changelogLine,
refs,
releaseDate: lastReleaseDate,
contributors,
});
matched = true;
}

Loading…
Cancel
Save