Skip to content

Commit

Permalink
og:image生成。
Browse files Browse the repository at this point in the history
  • Loading branch information
tai2 committed Nov 17, 2017
1 parent 01864d4 commit 3a43358
Show file tree
Hide file tree
Showing 39 changed files with 702 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ cache/
pelican.pid
srv.pid
.pelican
node_modules
Binary file added content/images/og/a-field-guide-to-debugging.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/abenomics-freelance.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/about_apple_swift.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/about_pythonjs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/android_mvp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/android_wear_design.png
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.
Binary file added content/images/og/bower_macglashan_mvp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/clean_architecture.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/crowdworks-sushi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/doctrine-best-practices.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/doctrine-join-with-syntax.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/email_validation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/freee-review.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/fsa-error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/github_client_howto.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/hexagonal_architecture.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/ios_settings_app.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/lgpl_and_appstore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/mpegla_and_ffmpeg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/mutt_and_notmuch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/nodejs-advent-calendar-2016.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/nodeschool_tokyo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/pelican_impression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/potel_mvp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/images/og/react-redux-reload.png
Binary file added content/images/og/real-world-redux.png
Binary file added content/images/og/the_git_object_model.png
Binary file added content/images/og/wants_for_designers.png
Binary file added content/images/og/wants_for_directors.png
Binary file added content/images/og/webpacker3.png
Binary file added content/images/og/websocket_bulktransfer_ios.png
Binary file added content/images/og/xhr_bulktransfer_ios.png
72 changes: 72 additions & 0 deletions ogimage.html
@@ -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>
39 changes: 39 additions & 0 deletions ogimage.js
@@ -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)

0 comments on commit 3a43358

Please sign in to comment.