Skip to content

Commit

Permalink
mime fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Nov 20, 2023
1 parent 87421db commit 06384af
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/crypto-frontmatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface FrontmatterLink {

export interface FrontmatterImage {
type: string;
mine: string;
mime: string;
size: {
width: number;
height: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto-frontmatter/index.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ it('should getFrontmatter of eip155:1/erc20:0x00000000008943c65cAf789FFFCF953bE1
],
images: [
{
type: 'logo',
mine: 'image/png',
type: 'icon',
mime: 'image/png',
size: {
width: 512,
height: 512,
Expand Down
2 changes: 1 addition & 1 deletion website/app/[caip2]/[slug]/AssetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function generateMetadata(caip19: string): Promise<Metadata> {

export async function Page(props: { caip19: string }): Promise<ReactElement> {
const frontmatter = await fetchFrontmatter(props.caip19);
const image = frontmatter.fields.images?.find((image) => image.type === 'logo');
const image = frontmatter.fields.images?.find((image) => image.type === 'icon');

return (
<main className="flex h-full min-w-0 flex-grow flex-col">
Expand Down
51 changes: 34 additions & 17 deletions workspace/contented-config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,47 @@ async function generateContentHash(filePath) {
* @param fileId {string}
* @param namespace {string}
* @param filePath {string}
* @return {Promise<[{mine: string, path: string}]>}
* @return {Promise<[{mime: string, path: string}]>}
*/
async function computeImageField(fileId, namespace, filePath) {
const reference = filePath.replace(/\/README\.md$/, '');
const pngLogoPath = join('frontmatter', namespace, reference, 'logo.png');
if (existsSync(pngLogoPath) === false) {
return [];
}

const size = imageSize(pngLogoPath);
async function computeAs({ type, from, ext, mime }) {
const pngLogoPath = join('frontmatter', namespace, reference, from);
if (existsSync(pngLogoPath) === false) {
return [];
}

const imagePath = (await generateContentHash(pngLogoPath)) + '.png';
await copyFile(pngLogoPath, join(`_${namespace}`, imagePath));
const size = imageSize(pngLogoPath);
const imagePath = (await generateContentHash(pngLogoPath)) + ext;
await copyFile(pngLogoPath, join(`_${namespace}`, imagePath));

return [
{
type: 'logo',
mine: 'image/png',
size: {
width: size.width,
height: size.height,
return [
{
type: type,
mime: mime,
size: {
width: size.width,
height: size.height,
},
path: imagePath,
},
path: imagePath,
},
];
}

return [
...(await computeAs({
type: 'icon',
from: 'logo.png',
ext: '.png',
mime: 'image/png',
})),
...(await computeAs({
type: 'icon',
from: 'logo.svg',
ext: '.svg',
mime: 'image/svg+xml',
})),
];
}

Expand Down

0 comments on commit 06384af

Please sign in to comment.