Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
og:image生成。
- Loading branch information
Showing
39 changed files
with
702 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ cache/ | |
pelican.pid | ||
srv.pid | ||
.pelican | ||
node_modules |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>OG Image Generator</title> | ||
<link href="https://fonts.googleapis.com/css?family=Spicy+Rice" rel="stylesheet"> | ||
<style> | ||
html { | ||
color: #333; | ||
background: #FFF8DC; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 35px 35px 0; | ||
} | ||
|
||
h1 { | ||
font-weight: bold; | ||
font-family: '游ゴシック体', sans-serif; | ||
line-height: 1.4; | ||
margin: 0; | ||
} | ||
|
||
address { | ||
background: rgba(0,0,0,0.9); | ||
font-weight: bold; font-family: 'Spicy Rice', cursive; | ||
font-style: normal; | ||
font-size: 13vh; | ||
text-align: right; | ||
line-height: 18vh; | ||
padding: 10px; | ||
position: absolute; | ||
bottom: 15px; | ||
right: 15px; | ||
} | ||
|
||
.icon { | ||
height: 18vh; | ||
vertical-align: middle; | ||
} | ||
|
||
.sitename { | ||
color: white; | ||
vertical-align: middle; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1 id="title"></h1> | ||
<address> | ||
<img class="icon" src="content/images/myicon_nomi.jpg"> | ||
<span class="sitename">blog.tai2.net</span> | ||
</address> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', async () => { | ||
const injectedProps = await getInjectedProps() | ||
const title = document.getElementById('title') | ||
title.innerHTML = injectedProps.title | ||
|
||
let fontSize = 100 // px dimension | ||
for (;;) { | ||
title.style.fontSize = fontSize + 'px' | ||
if (document.body.clientHeight <= window.innerHeight) { | ||
break | ||
} | ||
fontSize -= 1 | ||
} | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const process = require('process') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const puppeteer = require('puppeteer') | ||
const restructured = require('restructured').default | ||
|
||
function parseArticle(path) { | ||
const text = fs.readFileSync(path, 'utf8') | ||
const article = restructured.parse(text) | ||
const firstSection = article.children.find(child => child.type === 'section') | ||
const firstTitle = firstSection.children.find(child => child.type === 'title') | ||
const firstTitleText = firstTitle.children.find(child => child.type === 'text') | ||
return { | ||
path, | ||
title: firstTitleText.value, | ||
} | ||
} | ||
|
||
async function capture(article) { | ||
const viewport = { | ||
width: 1000, | ||
height: 500, | ||
} | ||
const injectedProps = { | ||
title: article.title, | ||
} | ||
const basename = path.basename(article.path, '.rst') | ||
|
||
const browser = await puppeteer.launch() | ||
const page = await browser.newPage() | ||
page.setViewport(viewport) | ||
await page.exposeFunction('getInjectedProps', () => injectedProps) | ||
await page.goto('file://' + path.resolve('ogimage.html')) | ||
await page.screenshot({path: `content/images/og/${basename}.png`}) | ||
await browser.close() | ||
} | ||
|
||
const article = parseArticle(process.argv[2]) | ||
capture(article) |
Oops, something went wrong.