Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3705f73

Browse files
convert image to base64 before rendering
1 parent99571df commit3705f73

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

‎api/pin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default async (req, res) => {
7070
}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
7171
);
7272

73-
repoData.openGraphImageUrl=awaitgetBase64URIFromImage(
73+
repoData.stringifiedRepoImage=awaitgetBase64URIFromImage(
7474
repoData.openGraphImageUrl,
7575
);
7676

‎src/cards/repo-card.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const renderRepoCard = (repo, options = {}) => {
6161
isTemplate,
6262
starCount,
6363
forkCount,
64-
openGraphImageUrl,
64+
stringifiedRepoImage,
6565
}=repo;
6666
const{
6767
hide_border=false,
@@ -143,7 +143,7 @@ const renderRepoCard = (repo, options = {}) => {
143143
height,
144144
border_radius,
145145
colors,
146-
imageUrl:show_image ?openGraphImageUrl :"",
146+
stringifiedRepoImage:show_image ?stringifiedRepoImage :"",
147147
});
148148

149149
card.disableAnimations();

‎src/common/Card.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Card {
1111
*@param {string?=} args.customTitle Card custom title.
1212
*@param {string?=} args.defaultTitle Card default title.
1313
*@param {string?=} args.titlePrefixIcon Card title prefix icon.
14-
*@param {string?=} args.imageUrl Card preview image.
14+
*@param {string?=} args.stringifiedRepoImage Card preview image.
1515
*@param {number?=} args.imageHeight Card preview image.
1616
*@param {object?=} args.colors Card colors arguments.
1717
*@param {string} args.colors.titleColor Card title color.
@@ -29,7 +29,7 @@ class Card {
2929
customTitle,
3030
defaultTitle="",
3131
titlePrefixIcon,
32-
imageUrl="",
32+
stringifiedRepoImage="",
3333
imageHeight=200,
3434
}){
3535
this.width=width;
@@ -41,7 +41,7 @@ class Card {
4141
this.border_radius=border_radius;
4242

4343
this.imageHeight=imageHeight;
44-
this.imageUrl=imageUrl;
44+
this.stringifiedRepoImage=stringifiedRepoImage;
4545

4646
// returns theme based colors with proper overrides and defaults
4747
this.colors=colors;
@@ -58,7 +58,7 @@ class Card {
5858
this.animations=true;
5959
this.a11yTitle="";
6060
this.a11yDesc="";
61-
if(this.imageUrl){
61+
if(this.stringifiedRepoImage){
6262
this.height+=this.imageHeight;
6363
this.paddingY+=this.imageHeight;
6464
}
@@ -214,13 +214,13 @@ class Card {
214214
*@returns {string} Renders social preview image
215215
*/
216216
renderImage=()=>{
217-
if(!this.imageUrl){
217+
if(!this.stringifiedRepoImage){
218218
return"";
219219
}
220220
return`
221221
<g data-testid="card-image" transform="translate(0, 0)">
222222
<image x="0" y="0" width="${this.width}" height="${this.imageHeight}"
223-
href="${this.imageUrl}">
223+
href="${this.stringifiedRepoImage}">
224224
</image>
225225
</g>`;
226226
};

‎src/fetchers/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type RepositoryData = {
2222
};
2323
forkCount:number;
2424
starCount:number;
25-
openGraphImageUrl:string;
25+
stringifiedRepoImage:string;
2626
};
2727

2828
exporttypeStatsData={

‎tests/renderRepoCard.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const data_repo = {
1818
},
1919
starCount:38000,
2020
forkCount:100,
21-
openGraphImageUrl:
22-
"https://repository-images.githubusercontent.com/266996769/1e4f2180-b194-11ea-9806-2395601f119b",
21+
stringifiedRepoImage:"data:image/png;base64,base64/image/string",
2322
},
2423
};
2524

@@ -350,7 +349,7 @@ describe("Test renderRepoCard", () => {
350349
expect(queryByTestId(document.body,"card-image")).toBeInTheDocument();
351350
expect(
352351
queryByTestId(document.body,"card-image").children[0],
353-
).toHaveAttribute("href",data_repo.repository.openGraphImageUrl);
352+
).toHaveAttribute("href",data_repo.repository.stringifiedRepoImage);
354353
});
355354

356355
it("should not render repo's social preview image by default",()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp