diff --git a/content/blog/2026/03/15/adding-stl-3d-previews-to-forgejo/index.md b/content/blog/2026/03/15/adding-stl-3d-previews-to-forgejo/index.md index fdae74f..2cd8358 100644 --- a/content/blog/2026/03/15/adding-stl-3d-previews-to-forgejo/index.md +++ b/content/blog/2026/03/15/adding-stl-3d-previews-to-forgejo/index.md @@ -80,13 +80,13 @@ The footer loads the viewer script as an ES module: ``` -The `{{AppSubUrl}}` template variable ensures the path works even if Forgejo is served under a subpath. +The `{{AppSubUrl}}` template variable ensures the path works even if Forgejo is served under a subpath. [`stlview.js`](https://codeberg.org/Codeberg-Infrastructure/build-deploy-forgejo/src/branch/codeberg-8/etc/gitea/public/assets/stlview.js) is the viewer itself, which we add in the next step. ## Step 3: The Three.js viewer -The viewer script (`stlview.js`) is based on [Codeberg's implementation](https://codeberg.org/Codeberg-Infrastructure/build-deploy-forgejo/src/branch/codeberg-8/etc/gitea/public/assets/stlview.js). It uses Three.js r160 with ES modules, bundled locally so there's no CDN dependency. +The viewer script is based on [Codeberg's `stlview.js`](https://codeberg.org/Codeberg-Infrastructure/build-deploy-forgejo/src/branch/codeberg-8/etc/gitea/public/assets/stlview.js), so start by copying that file into `custom/public/assets/stlview.js`. It uses Three.js r160 with ES modules, bundled locally so there's no CDN dependency. -Here's the high-level flow: +The snippets below are there to explain what the script does, they are not the complete file. Here's the high-level flow: 1. **URL detection**: Check if the current page path ends with `.stl`. If not, bail out. 2. **Raw URL construction**: Replace `/src/` in the URL with `/raw/` to get the actual file download URL. @@ -134,6 +134,11 @@ custom/public/assets/ └── TrackballControls.js ``` +Where each file comes from: + +- `stlview.js`: [Codeberg's version](https://codeberg.org/Codeberg-Infrastructure/build-deploy-forgejo/src/branch/codeberg-8/etc/gitea/public/assets/stlview.js). +- `three.js/`: the [r160 release](https://github.com/mrdoob/three.js/releases/tag/r160) of Three.js, keeping only the three modules listed above. + ## Result Preview of an STL file in Forgejo