Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.
/ cardserver Public archive

๐ŸŒ‡๏ธ A simple social media card renderer written in Puppeteer โ€“ screenshot card-like webpages on-the-fly

License

Notifications You must be signed in to change notification settings

stevelacey/cardserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

23 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cardserver

A simple social media card renderer written using Puppeteer โ€“ screenshot card-like webpages on-the-fly

Cardserver is largely based on how Pieter generates shareable pictures for Nomad List โ€“ built for Coworkations

Warning

This project is no longer maintained, check out stevelacey/cloudflare-screenshot

Coworkations ๐Ÿ“„ HTML ๐Ÿ–ผ๏ธ PNG Hacker Paradise: Cape Town South Africa ๐Ÿ“„ HTML ๐Ÿ–ผ๏ธ PNG
Nomad Cruise VI: Spain To Greece ๐Ÿ“„ HTML ๐Ÿ–ผ๏ธ PNG PACK: Ubud Bali ๐Ÿ“„ HTML ๐Ÿ–ผ๏ธ PNG

Setup

npm install -g cardserver
cardserver

Usage

Cardserver performs HTML requests based on PNG requests like so:

๐ŸŒ‡ PNG (cardserver request) ๐Ÿ“„ HTML (webserver request)
https://steve.ly/cards/steve.png https://steve.ly/cards/steve
https://coworkations.com/cards/coworkations.png https://coworkations.com/cards/coworkations
https://coworkations.com/cards/hacker-paradise.png https://coworkations.com/cards/hacker-paradise
https://coworkations.com/cards/pack/ubud-bali-2.png https://coworkations.com/cards/pack/ubud-bali-2

Markup

Youโ€™ll want meta tags something like these:

<meta itemprop="image" content="https://coworkations.com/cards/coworkations.png">
<meta property="og:image" content="https://coworkations.com/cards/coworkations.png">
<meta name="twitter:image" content="https://coworkations.com/cards/coworkations.png">

Caching

Cardserver serves basic caching headers and works great with Cloudflare, generated images are cached in /tmp/cards and replaced after 1 week, empty the directory if you want to clear the cache

The script serves a cache maxage of a week, and requires .png file extension so that Cloudflare will cache it without any additional configuration (page rules are required otherwise)

Debugging

Fonts

If you have any issues with fonts you may need to download them and put them somewhere like /usr/share/fonts/truetype (Ubuntu), you can get the URL to Googleโ€™s TTFโ€™s by blanking out your User-Agent (otherwise itโ€™ll probably serve you WOFF2โ€™s)

NGINX

The simplest way to hook cardserver up is to route all PNG traffic to it via NGINX:

location ~ ^/cards/.*\.png$ {
    proxy_pass http://127.0.0.1:9100;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
}

Supervisor

Supervisor is handy to keep cardserver running:

[program:cardserver]
command = cardserver
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/cardserver.log
redirect_stderr = true

About

๐ŸŒ‡๏ธ A simple social media card renderer written in Puppeteer โ€“ screenshot card-like webpages on-the-fly

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published