Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all documentation example images to webp using sharp #4329

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions build/convert-doc-images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from 'fs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this script is needed as is, but it would be great if you could add it to the image generation script.
Note that I have made a few changes to this script in the sky branch.

import sharp from 'sharp';

const exampleName = process.argv[2];
const folderPath = './docs/assets/examples/';
function listFilesInFolder(folderPath: string): string[] {
try {
// Read the contents of the folder
const files = fs.readdirSync(folderPath);
return files;
} catch (error) {
return [`Error: ${error.message}`];
}
}

function generateWebPImage(inputFileName: string) {
const outputFileName = inputFileName.replace('.png', '.webp');
const inputFilePath = `${folderPath}${inputFileName}`;
const outputFilePath = `${folderPath}${outputFileName}`;

convertToWebP(inputFilePath, outputFilePath);
}

function convertToWebP(inputFile: string, outputFile: string) {
sharp(inputFile)
.webp({quality: 90, lossless: false})
.toFile(outputFile)
.then(() => {
console.log(`Converted '${inputFile}' to '${outputFile}'`);
})
.catch((err) => {
console.log(`Error while converting '${inputFile}' to '${outputFile}'`);
console.log(err);
});
}

if (exampleName) {
generateWebPImage(`${exampleName}.png`);
} else {
listFilesInFolder(folderPath)
.filter((fileName) => fileName.endsWith('.png'))
.forEach(generateWebPImage);
}
2 changes: 1 addition & 1 deletion build/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function generateMarkdownIndexFileOfAllExamples(indexArray: HtmlDoc[]): string {
indexMarkdown += `
## [${indexArrayItem.title}](./${indexArrayItem.mdFileName})

![${indexArrayItem.description}](../assets/examples/${indexArrayItem.mdFileName!.replace('.md', '.png')}){ loading=lazy }
![${indexArrayItem.description}](../assets/examples/${indexArrayItem.mdFileName!.replace('.md', '.webp')}){ loading=lazy }

${indexArrayItem.description}
`;
Expand Down
6 changes: 4 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ Examples are written as regular html files in `test/examples`. Each example shou
When you create a new example, you **must** make an accompanying image.

1. Run `npm run generate-images <example-file-name>`. The script will take a screenshot of the map in the example and save it to `docs/assets/examples/`.
2. Optimize the image with [compresspng](https://compresspng.com/) to reduce the file size. (Optional)
3. Commit the image.
1. Run `npm run convert-images <example-file-name>`. The script will convert the screenshot stored in the folder `docs/assets/examples/` to webp.
3. Commit both images.

For some examples, `npm run generate-images` does not generate an ideal image. In these cases, you can interact with the map after running the command before the screenshot is taken, or take a screenshot yourself by running the site locally with `npm start`, take a screenshot and save it in the `docs/assets/examples/` folder.

To regenerate all images, run `npm run generate-images`. Note that this doesn't support interaction and examples that require manual interaction (e.g. popups) will need to be manually redone afterward. This feature is experimental and may crash before successfully generating all examples.

To convert all images, run `npm run convert-images`. Note that it will take original screenshots in PNG format and regenerate/override all existing webp images stored on the `docs/assets/examples/` folder.

## Committing and Publishing Documentation

When a new MapLibre GL JS release goes out the documentation will be released with it.
Expand Down
Binary file added docs/assets/examples/3d-buildings.webp
Binary file not shown.
Binary file added docs/assets/examples/3d-extrusion-floorplan.webp
Binary file not shown.
Binary file added docs/assets/examples/3d-terrain.webp
Binary file not shown.
Binary file added docs/assets/examples/add-3d-model-babylon.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/add-3d-model.webp
Binary file not shown.
Binary file added docs/assets/examples/add-a-marker.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/add-image-animated.webp
Binary file not shown.
Binary file added docs/assets/examples/add-image-generated.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/add-image-stretchable.webp
Binary file not shown.
Binary file added docs/assets/examples/add-image.webp
Binary file not shown.
Binary file added docs/assets/examples/animate-a-line.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/animate-images.webp
Binary file not shown.
Binary file added docs/assets/examples/animate-marker.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/attribution-position.webp
Binary file not shown.
Binary file added docs/assets/examples/camera-animation.webp
Binary file not shown.
Binary file added docs/assets/examples/canvas-source.webp
Binary file not shown.
Binary file added docs/assets/examples/center-on-symbol.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/change-case-of-labels.webp
Binary file not shown.
Binary file added docs/assets/examples/check-for-support.webp
Binary file not shown.
Binary file added docs/assets/examples/cluster-html.webp
Binary file not shown.
Binary file added docs/assets/examples/cluster.webp
Binary file not shown.
Binary file added docs/assets/examples/color-switcher.webp
Binary file not shown.
Binary file added docs/assets/examples/contour-lines.webp
Binary file not shown.
Binary file added docs/assets/examples/cooperative-gestures.webp
Binary file not shown.
Binary file added docs/assets/examples/custom-marker-icons.webp
Binary file not shown.
Binary file added docs/assets/examples/custom-style-layer.webp
Binary file not shown.
Binary file added docs/assets/examples/data-driven-lines.webp
Binary file not shown.
Binary file added docs/assets/examples/disable-rotation.webp
Binary file not shown.
Binary file added docs/assets/examples/disable-scroll-zoom.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/drag-a-marker.webp
Binary file not shown.
Binary file added docs/assets/examples/drag-a-point.webp
Binary file not shown.
Binary file added docs/assets/examples/fallback-image.webp
Binary file not shown.
Binary file added docs/assets/examples/fill-pattern.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/filter-markers.webp
Binary file not shown.
Binary file added docs/assets/examples/filter-within-layer.webp
Binary file not shown.
Binary file added docs/assets/examples/fitbounds.webp
Binary file not shown.
Binary file added docs/assets/examples/flyto-options.webp
Binary file not shown.
Binary file added docs/assets/examples/flyto.webp
Binary file not shown.
Binary file added docs/assets/examples/fullscreen.webp
Binary file not shown.
Binary file added docs/assets/examples/game-controls.webp
Binary file not shown.
Binary file added docs/assets/examples/geocoder.webp
Binary file not shown.
Binary file added docs/assets/examples/geojson-layer-in-stack.webp
Binary file not shown.
Binary file added docs/assets/examples/geojson-line.webp
Binary file not shown.
Binary file added docs/assets/examples/geojson-markers.webp
Binary file not shown.
Binary file added docs/assets/examples/geojson-polygon.webp
Binary file not shown.
Binary file added docs/assets/examples/heatmap-layer.webp
Binary file not shown.
Binary file added docs/assets/examples/hover-styles.webp
Binary file not shown.
Binary file added docs/assets/examples/interactive-false.webp
Binary file not shown.
Binary file added docs/assets/examples/jump-to.webp
Binary file not shown.
Binary file added docs/assets/examples/language-switch.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/line-gradient.webp
Binary file not shown.
Binary file added docs/assets/examples/live-geojson.webp
Binary file not shown.
Binary file added docs/assets/examples/live-update-feature.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/local-geojson.webp
Binary file not shown.
Binary file added docs/assets/examples/local-ideographs.webp
Binary file not shown.
Binary file added docs/assets/examples/locate-user.webp
Binary file not shown.
Binary file added docs/assets/examples/map-tiles.webp
Binary file not shown.
Binary file added docs/assets/examples/mapbox-gl-draw.webp
Binary file not shown.
Binary file added docs/assets/examples/mapbox-gl-rtl-text.webp
Binary file not shown.
Binary file added docs/assets/examples/measure.webp
Binary file not shown.
Binary file added docs/assets/examples/mouse-position.webp
Binary file not shown.
Binary file added docs/assets/examples/multiple-geometries.webp
Binary file not shown.
Binary file added docs/assets/examples/navigation.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/pmtiles.webp
Binary file not shown.
Binary file added docs/assets/examples/polygon-popup-on-click.webp
Binary file not shown.
Binary file added docs/assets/examples/popup-on-click.webp
Binary file not shown.
Binary file added docs/assets/examples/popup-on-hover.webp
Binary file not shown.
Binary file added docs/assets/examples/popup.webp
Binary file not shown.
Binary file added docs/assets/examples/queryrenderedfeatures.webp
Binary file not shown.
Binary file added docs/assets/examples/render-world-copies.webp
Binary file not shown.
Binary file added docs/assets/examples/restrict-bounds.webp
Binary file not shown.
Binary file added docs/assets/examples/satellite-map.webp
Binary file not shown.
Binary file added docs/assets/examples/scroll-fly-to.webp
Binary file not shown.
Binary file added docs/assets/examples/set-perspective.webp
Binary file not shown.
Binary file added docs/assets/examples/set-popup.webp
Binary file not shown.
Binary file added docs/assets/examples/simple-map.webp
Binary file not shown.
Binary file added docs/assets/examples/third-party.webp
Binary file not shown.
Binary file added docs/assets/examples/timeline-animation.webp
Binary file not shown.
Binary file added docs/assets/examples/toggle-deckgl-layer.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/vector-source.webp
Binary file not shown.
Binary file added docs/assets/examples/video-on-a-map.webp
Binary file not shown.
Binary file not shown.
Binary file added docs/assets/examples/wms.webp
Binary file not shown.
Binary file added docs/assets/examples/zoomto-linestring.webp
Binary file not shown.
Loading
Loading