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
const puppeteerLottie = require("puppeteer-lottie"); | |
const fs = require("fs"); | |
const baseInputDir = "lotties/"; | |
const baseOutputDir = "lotties-rendered/"; | |
const outputExtension = '.mp4'; | |
(async () => { | |
await run(); | |
})(); | |
async function run() { | |
const files = fs.readdirSync(baseInputDir); | |
await convertLotties(files); | |
generateIndex(files); | |
} | |
async function convertLotties(files) { | |
files.forEach(async (file) => { | |
await renderLottie(baseInputDir + file, baseOutputDir + file); | |
}); | |
} | |
async function renderLottie(inputFilePath, outputFilePath) { | |
await puppeteerLottie({ | |
path: inputFilePath, | |
output: outputFilePath.replace('.json', outputExtension) | |
}); | |
} | |
function generateIndex(files) { | |
const header = ` | |
<link rel="stylesheet" href="styles/index.css"> | |
<title>Lottie Catalog</title> | |
`; | |
var body = ''; | |
files.forEach(file => { | |
const renderedFile = baseOutputDir + file.replace('.json', outputExtension); | |
body += ` | |
<div class="lottie"> | |
<p class="lottie-title">` + file + `</p> | |
<video controls muted autoplay loop width="400"> | |
<source src="` + renderedFile + `" type="video/mp4"> | |
</video> | |
</div> | |
`; | |
}); | |
const html = ` | |
<!DOCTYPE html> | |
<html> | |
<head>` + header + `</head> | |
<body>` + body + `</body> | |
</html> | |
`; | |
const stream = fs.createWriteStream("index.html"); | |
stream.once('open', function(fd) { | |
stream.end(html); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment