Skip to content

Commit

Permalink
fix preview gen script for articles
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeygrigorev committed May 3, 2022
1 parent a1a2a61 commit 756c263
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
34 changes: 23 additions & 11 deletions previews/render.js
Expand Up @@ -11,15 +11,27 @@ const output = args[3];


const render = async (config, output) => {
const browser = await puppeteer.launch({
defaultViewport: {
width: 940,
height: 550,
isLandscape: true
},
executablePath: 'chromium-browser',
args: ['--no-sandbox'],
});
let browser = null;
if (process.platform === 'win32') {
browser = await puppeteer.launch({
defaultViewport: {
width: 940,
height: 550,
isLandscape: true
},
args: ['--no-sandbox'],
});
} else {
browser = await puppeteer.launch({
defaultViewport: {
width: 940,
height: 550,
isLandscape: true
},
executablePath: 'chromium-browser',
args: ['--no-sandbox'],
});
}

const page = await browser.newPage();

Expand All @@ -31,14 +43,14 @@ const render = async (config, output) => {
const subtitle = config.subtitle;

const authors = config.authors.map(author => {
const dataPath = `_people/${author}.md`;
const dataPath = `../_people/${author}.md`;

const data = fs.readFileSync(dataPath, 'utf8');
const attributes = fm(data).attributes;

const name = attributes.title;

const image = 'file://' + path.resolve(`./images/authors/${author}.jpg`);
const image = 'file://' + path.resolve(`../images/authors/${author}.jpg`);

return { name, image };
});
Expand Down
28 changes: 20 additions & 8 deletions scripts/generate-post-preview.sh
@@ -1,11 +1,23 @@
# else nvm won't load
. ~/.nvm/nvm.sh
nvm use v10.17.0

# docker run -it \
# -v $(pwd)/_posts:/app/_posts \
# -v $(pwd)/_people:/app/_people \
# -v $(pwd)/images:/app/images \
# -u $(id -u ${USER}):$(id -g ${USER}) \
# datatalks-cover-generator \
# _posts/${POST}.md \
# images/posts/${POST}/cover.jpg


cd previews

POST=$1

docker run -it \
-v $(pwd)/_posts:/app/_posts \
-v $(pwd)/_people:/app/_people \
-v $(pwd)/images:/app/images \
-u $(id -u ${USER}):$(id -g ${USER}) \
datatalks-cover-generator \
_posts/${POST}.md \
images/posts/${POST}/cover.jpg
echo "post: ${POST}"

node render.js \
../_posts/${POST}.md \
../images/posts/${POST}/cover.jpg

0 comments on commit 756c263

Please sign in to comment.