Skip to content

Commit 29e9132

Browse files
committed
add : 다크모드
1 parent 0244e2b commit 29e9132

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

api/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const createCard = require('../src/cards/new-log');
2+
const createCardDark = require('../src/cards/new-log-black');
23
const fetchPost = require('../src/fetchers/post-fetcher');
34

45

56
module.exports = async (req, res) => {
6-
const { name, tag } = req.query;
7+
const { name, tag, background } = req.query;
78
res.setHeader('Content-Type', 'image/svg+xml');
89
try{
910
const post = await fetchPost(name, tag);
10-
return res.send(createCard(post))
11+
return res.send(background==='dark' ? createCardDark(post) : createCard(post))
1112
} catch(e){
1213
return res.send(e.message)
1314
}

src/cards/new-log-black.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const { koCheck, replaceAll } = require("../utils")
2+
3+
const createCardTitle = (username, likes) => {
4+
const likeX = likes > 99 ? 365 : likes > 9 ? 370 : 380
5+
return `
6+
<g data-testid="card-title" transform="translate(25, 35)">
7+
<g transform="translate(0, 0)">
8+
<text x="0" y="0" class="header" data-testid="header">${username}.log</text>
9+
<svg width="30" x="390" y="-10" height="13" viewBox="0 0 30 13" fill="none" xmlns="http://www.w3.org/2000/svg">
10+
<path d="M11.25 0L7.5 2.26044L3.75 0L0 2.82555V6.78133L7.5 12.4324L15 6.78133V2.82555L11.25 0Z" fill="#20c997"/>
11+
</svg>
12+
<text x="${likeX}" class="heart-count" data-testid="heart-count">${likes}</text>
13+
</g>
14+
</g>
15+
`
16+
}
17+
18+
const createCardBody = ({title, short_description}) => {
19+
return `
20+
<g data-testid="main-card-body" transform="translate(0, 45)">
21+
<svg data-testid="lang-items" x="25" width="400" height="40" viewBox="0 0 400 40">
22+
<g transform="translate(0, 0)">
23+
<text data-testid="lang-name" x="2" y="15" class="log-title">${title}</text>
24+
<text ata-testid="lang-description" x="2" y="35" class="log-description">${short_description}</text>
25+
</g>
26+
</svg>
27+
</g>
28+
`
29+
}
30+
31+
const createCardBottom = ({tags}) => {
32+
let prev=25;
33+
return `
34+
<g data-testid="main-card-bottom" transform="translate(0, 40)">
35+
${
36+
tags.map((element) => {
37+
const text=replaceAll(element, ' ', '');
38+
const blakSize=element.length-text.length;
39+
const size=(koCheck(text) ? text.length*12+12 : text.length*9+5)+blakSize*2;
40+
const pos=prev;
41+
if(prev+size > 400) return;
42+
else prev+=size+5;
43+
return`
44+
<svg data-testid="lang-items" x="${pos}" width="${size}" viewBox="0 0 ${size} 19">
45+
<g style="position: relative;">
46+
<rect width="${size}" height="19.5367" rx="9.76834" fill="#F1F3F5"/>
47+
<text data-testid="lang-name" text-anchor="middle" x="${size/2}" y="13" class="tag-item">${element}</text>
48+
</g>
49+
</svg>
50+
`
51+
})
52+
}
53+
</g>
54+
`
55+
}
56+
57+
const cardStyle =`
58+
<style>
59+
.header {
60+
font: bold 14px 'Segoe UI', Ubuntu, Sans-Serif;
61+
fill: #20c997;
62+
animation: fadeInAnimation 0.8s ease-in-out forwards;
63+
}
64+
.log-title { font: bold 14px 'Segoe UI', Ubuntu, Sans-Serif; fill: white }
65+
.log-description { font-size: 12px; fill: white}
66+
.tag-item { font-size: 12px; fill: #0CA678;}
67+
.heart-count { font-size: 12px; fill: #20c997;}
68+
</style>
69+
`
70+
const createCardDark = (data) => {
71+
return `
72+
<svg xmlns="http://www.w3.org/2000/svg" width="450" height="130" viewBox="0 0 450 130" fill="none">
73+
${cardStyle}
74+
<rect data-testid="card-bg" x="0.5" y="0.5" rx="4.5" height="99%" stroke="#e4e2e2" width="449" fill="#24292e" stroke-opacity="1"/>
75+
${createCardTitle(data.user.username, data.likes)}
76+
${createCardBody(data)}
77+
${createCardBottom(data)}
78+
</svg>
79+
`
80+
}
81+
82+
module.exports=createCardDark;

0 commit comments

Comments
 (0)