FMG-8: link stlview.js to the Codeberg source in the guide #4
1 changed files with 8 additions and 3 deletions
|
|
@ -80,13 +80,13 @@ The footer loads the viewer script as an ES module:
|
|||
<script src="{{AppSubUrl}}/assets/stlview.js" type="module"></script>
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
<img src="screenshot.png" alt="Preview of an STL file in Forgejo">
|
||||
|
|
|
|||
Loading…
Reference in a new issue