Skip to content

Commit

Permalink
docs: add vitepress
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Mar 20, 2024
1 parent 5a6f0b5 commit 416c1be
Show file tree
Hide file tree
Showing 6 changed files with 998 additions and 72 deletions.
24 changes: 24 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
20 changes: 20 additions & 0 deletions docs/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "vitepress";

// https://vitepress.vuejs.org/config/app-configs
export default defineConfig({
lang: "en-US",
title: "URL to PNG",
description:
"Selfhosted. URL to PNG utility featuring parallel rendering using Playwright for screenshots and with storage caching via Local, S3, or CouchDB.",
themeConfig: {
repo: "vuejs/vitepress",
docsDir: "docs",
editLinks: true,
editLinkText: "Edit this page on GitHub",
nav: [
{ text: "Guide", link: "/guide/" },
{ text: "Config Reference", link: "/config/" },
{ text: "Github", link: "https://github.com/jasonraimondi/url-to-png" },
],
},
});
150 changes: 150 additions & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<h1 align="center">URL to PNG</h1>

A URL to PNG generator over HTTP with a fairly simple API accessed via query params passed to the server.

## Getting Started

### Docker

Run the following command:

```
docker run --rm -p 3089:3089 ghcr.io/jasonraimondi/url-to-png
```

On the hub: [Link to DockerHub](https://hub.docker.com/r/jasonraimondi/url-to-png/)

### Local Serve

Serve the project

```
git clone [email protected]:jasonraimondi/url-to-png.git
cd url-to-png
pnpm install
pnpm dev
```

## Query Params

- `url: string` - Valid URL to be captured - **Required**
- `width: number` - Width of output screenshot - **Optional** - Default: `250`
- `height: number` - Height of output screenshot - **Optional** - Default: `250`
- `viewPortWidth: number` - Width of render viewport - **Optional** - Default: `1080`
- `viewPortHeight: number` - Height of render viewport - **Optional** - Default: `1080`
- `forceReload: boolean` - Force cached image reload - **Optional** - Default: `false`
- `isMobile: boolean` - Adds mobile flag to user agent - **Optional** - Default: `false
- `isFullPage: boolean` - Render full page instead of viewport crop - **Optional** - Default: `false`
- `isDarkMode: boolean` - Prefer color scheme dark - **Optional** - Default: `false`
- `deviceScaleFactor: number` - Specify device scale factor (can be thought of as dpr) - **Optional** - Default: `1`

Try it out at `localhost:3089?url=https://www.jasonraimondi.com&isDarkMode=true` and you should get back an image capture of my website homepage.

All sorts of combos work:

```
http://localhost:3089?url=https://jasonraimondi.com
http://localhost:3089?url=https://jasonraimondi.com&forceReload=true
http://localhost:3089?url=https://jasonraimondi.com&isFullPage=true
http://localhost:3089?url=https://jasonraimondi.com&isMobile=true
http://localhost:3089?url=https://jasonraimondi.com&isDarkMode=true
http://localhost:3089?url=https://jasonraimondi.com&width=400&height=400
http://localhost:3089?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&isFullPage=true&isMobile=true&width=400&height=400&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&isMobile=true&isFullPage=true&viewPortWidth=375&width=375&deviceScaleFactor=1
```

## System Requirements

The following is cut from the Playwright documentation, please view the [official system requirement documentation](https://playwright.dev/docs/1.3.0/intro/#system-requirements) for the most up to date requirements guide.

Playwright requires Node.js version 10.15 or above. The browser binaries for Chromium, Firefox and WebKit work across the 3 platforms (Windows, macOS, Linux):

* **Windows**: Works with Windows and Windows Subsystem for Linux (WSL).
* **macOS**: Requires 10.14 or above.
* **Linux**: Depending on your Linux distribution, you might need to install additional dependencies to run the browsers.
* **Firefox** requires Ubuntu 18.04+
* For **Ubuntu 18.04**, the additional dependencies are defined in the [playwright Docker image](https://github.com/microsoft/playwright/blob/master/utils/docker/Dockerfile.bionic), which is based on Ubuntu.

## Allow List

Allow domain specific requests by passing in an ALLOW_LIST. The list should be **comma separated**, **not include spaces**, and should be the **domain name only**.

If this value is either `undefined || ""`, url-to-png will allow any domain to be rendered.

```
ALLOW_LIST=jasonraimondi.com,github.com
```

## Playwright Options

Please see the Playwright API documentation [here](https://playwright.dev/docs/api/class-page#pagegotourl-options) for further knowledge.

```
BROWSER_TIMEOUT=
BROWSER_WAIT_UNTIL=
```

#### `BROWSER_TIMEOUT`

The maximum navigation time in milliseconds, pass 0 to disable timeout. The default value is 10000

#### `BROWSER_WAIT_UNTIL`

When playwright to considers the navigation succeeded. The default value for this option is `domcontentloaded`

Valid Options:

- `'load'` - consider operation to be finished when the `load` event is fired.
- `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
- `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.

## Image Storage / Cache

NOTE: If you are running in Docker, you should skip the .env and load the environment variables into your container.

You are going to need to copy the environment file to use any of the storage options. By default no images are cached.

```
cp .env.sample .env
```

#### AWS S3

To use Amazon S3 set `STORAGE_PROVIDER=s3`, ensure the following variables are loaded in your `.env`:

```
STORAGE_PROVIDER=s3
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_ENDPOINT_URL_S3=
AWS_BUCKET=
```

#### CouchDB

To use CouchDB set `STORAGE_PROVIDER=couchdb`, ensure the following variables are loaded in your `.env`:

```
STORAGE_PROVIDER=couchdb
COUCH_DB_PROTOCOL=
COUCH_DB_HOST=
COUCH_DB_USER=
COUCH_DB_PASS=
```

#### Filesystem

To use your local filesystem, set `STORAGE_PROVIDER=filesystem`, ensure the following variables are loaded in your `.env`:

```
STORAGE_PROVIDER=filesystem
IMAGE_STORAGE_PATH=/tmp/foo
```

## Sources

- Upstream Repository: [https://git.jasonraimondi.com/jason/url-to-png](https://git.jasonraimondi.com/jason/url-to-png)
- Logo from [https://www.hipsterlogogenerator.com/](https://www.hipsterlogogenerator.com/)
21 changes: 21 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "vitepress-project",
"private": true,
"type": "module",
"scripts": {
"dev": "vitepress dev docs",
"build": "vitepress build docs",
"serve": "vitepress serve docs"
},
"devDependencies": {
"vue": "3.2.44",
"vitepress": "1.0.0-alpha.28"
},
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"@algolia/client-search"
]
}
}
}
Loading

0 comments on commit 416c1be

Please sign in to comment.