Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(slots-footer-index) : 通过配置 icon的值为图片URL来项显示图标 #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/slots/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@ const Footer: FC = () => {

const footer = themeConfig.footerConfig as IFooter;

const columns =
footer?.columns === false
? undefined
: getColumns({ github: githubUrl || (pkg as any).homepage });
const columns = footer?.columns
? footer.columns
: getColumns({ github: githubUrl || (pkg as any).homepage });

// icons 为图片地址时,转为HTMLElement 函数
const updateIconToImgElement = (item: any) => {
if (
item?.icon &&
typeof item.icon === 'string' &&
item.icon.match(/\.(png|jpeg|jpg|gif|svg|webp)$/) !== null
) {
item.icon = <img src={item.icon} alt="" />;
}
};
// 递归函数
const updateIconsRecursively = (item: any) => {
updateIconToImgElement(item);
if (item?.items && item.items instanceof Array) {
item.items.forEach((_item: any) => {
updateIconsRecursively(_item);
});
}
};
// 处理图片地址
columns.forEach(updateIconsRecursively);

const bottomFooter = footer?.bottom || themeConfig.footer;
const copyright = footer?.copyright || `Copyright © 2022-${new Date().getFullYear()}`;
Expand Down