Browse Source

Merge pull request #101 from jrtechs/svg-recent

added route to create svg with recent blog posts
pull/102/head
Jeffery Russell 4 years ago
committed by GitHub
parent
commit
46bedb7e93
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 0 deletions
  1. +48
    -0
      routes/api/index.js

+ 48
- 0
routes/api/index.js View File

@ -26,6 +26,54 @@ routes.get('/getPostsIds/:category', (request, result) =>
})
});
function getURL(sqlData)
{
return "https://jrtechs.net/" + sqlData.category + "/" + sqlData.url;
}
routes.get('/recentSVG', (request, result) =>
{
sql.getRecentPosts(4).then((sqlData)=>
{
result.writeHead(200, {'Content-Type': 'image/svg+xml',
'Cache-Control': 'public, max-age=2678400',
'Vary': 'Accept-Encoding'});
var res = `
<svg width="806" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<title>background</title>
<rect x="-1" y="-1" width="808" height="202" id="canvas_background" fill="#fff"/>
<g id="canvasGrid" display="none">
<rect id="svg_1" width="100%" height="100%" x="0" y="0" stroke-width="0" fill="url(#gridpattern)"/>
</g>
</g>
<g>
<title>Jrtechs</title>
<a xlink:href="https://jrtechs.net">
<text fill="#498FBE" stroke="#000" stroke-width="0" stroke-opacity="null" x="36.5" y="40.5" id="svg_6" font-size="24" font-family="Oswald, sans-serif" text-anchor="start" xml:space="preserve" font-weight="bold">Recent Blog Posts</text>
</a>
<a xlink:href="${getURL(sqlData[0])}">
<text fill="#000000" stroke="#000" stroke-width="0" stroke-opacity="null" x="65.5" y="73.5" id="svg_7" font-size="20" font-family="Oswald, sans-serif" text-anchor="start" xml:space="preserve" font-weight="normal">- ${sqlData[0].name}</text>
</a>
<a xlink:href="${getURL(sqlData[1])}">
<text fill="#000000" stroke="#000" stroke-width="0" stroke-opacity="null" x="65.5" y="106.5" id="svg_7" font-size="20" font-family="Oswald, sans-serif" text-anchor="start" xml:space="preserve" font-weight="normal">- ${sqlData[1].name}</text>
</a>
<a xlink:href="${getURL(sqlData[2])}">
<text fill="#000000" stroke="#000" stroke-width="0" stroke-opacity="null" x="65.5" y="139.5" id="svg_7" font-size="20" font-family="Oswald, sans-serif" text-anchor="start" xml:space="preserve" font-weight="normal">- ${sqlData[2].name}</text>
</a>
<a xlink:href="${getURL(sqlData[3])}">
<text fill="#000000" stroke="#000" stroke-width="0" stroke-opacity="null" x="65.5" y="172.5" id="svg_7" font-size="20" font-family="Oswald, sans-serif" text-anchor="start" xml:space="preserve" font-weight="normal">- ${sqlData[3].name}</text>
</a>
</g>
</svg>`;
result.write(res);
result.end();
}).catch((err)=>
{
result.status(404).json({error: 404}).end();
})
});
routes.get('/posts', (request, result) =>
{

Loading…
Cancel
Save