Skip to content

Commit 316db0f

Browse files
authored
Add documentation to display STL preview (#11181)
* Update customizing-gitea.en-us.md * Update customizing-gitea.en-us.md * only load assets when needed * remove useless var * fix missing 'i' modifier
1 parent fcc8cdd commit 316db0f

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,89 @@ You can then add blocks like the following to your markdown:
180180

181181
The script will detect tags with `class="language-plantuml"`, but you can change this by providing a second argument to `parsePlantumlCodeBlocks`.
182182

183+
#### Example: STL Preview
184+
185+
You can display STL file directly in Gitea by adding:
186+
```html
187+
<script>
188+
function lS(src){
189+
return new Promise(function(resolve, reject) {
190+
let s = document.createElement('script')
191+
s.src = src
192+
s.addEventListener('load', () => {
193+
resolve()
194+
})
195+
document.body.appendChild(s)
196+
});
197+
}
198+
199+
if($('.view-raw>a[href$=".stl" i]').length){
200+
$('body').append('<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">');
201+
Promise.all([lS("/Madeleine.js/src/lib/stats.js"),lS("/Madeleine.js/src/lib/detector.js"), lS("/Madeleine.js/src/lib/three.min.js"), lS("/Madeleine.js/src/Madeleine.js")]).then(function() {
202+
$('.view-raw').attr('id', 'view-raw').attr('style', 'padding: 0;margin-bottom: -10px;');
203+
new Madeleine({
204+
target: 'view-raw',
205+
data: $('.view-raw>a[href$=".stl" i]').attr('href'),
206+
path: '/Madeleine.js/src'
207+
});
208+
$('.view-raw>a[href$=".stl"]').remove()
209+
});
210+
}
211+
</script>
212+
```
213+
to the file `templates/custom/footer.tmpl`
214+
215+
You also need to download the content of the library [Madeleine.js](https://jinjunho.github.io/Madeleine.js/) and place it under `custom/public/` folder.
216+
217+
You should end-up with a folder structucture similar to:
218+
```
219+
custom/templates
220+
-- custom
221+
`-- footer.tmpl
222+
custom/public
223+
-- Madeleine.js
224+
|-- LICENSE
225+
|-- README.md
226+
|-- css
227+
| |-- pygment_trac.css
228+
| `-- stylesheet.css
229+
|-- examples
230+
| |-- ajax.html
231+
| |-- index.html
232+
| `-- upload.html
233+
|-- images
234+
| |-- bg_hr.png
235+
| |-- blacktocat.png
236+
| |-- icon_download.png
237+
| `-- sprite_download.png
238+
|-- models
239+
| |-- dino2.stl
240+
| |-- ducati.stl
241+
| |-- gallardo.stl
242+
| |-- lamp.stl
243+
| |-- octocat.stl
244+
| |-- skull.stl
245+
| `-- treefrog.stl
246+
`-- src
247+
|-- Madeleine.js
248+
|-- css
249+
| `-- Madeleine.css
250+
|-- icons
251+
| |-- logo.png
252+
| |-- madeleine.eot
253+
| |-- madeleine.svg
254+
| |-- madeleine.ttf
255+
| `-- madeleine.woff
256+
`-- lib
257+
|-- MadeleineConverter.js
258+
|-- MadeleineLoader.js
259+
|-- detector.js
260+
|-- stats.js
261+
`-- three.min.js
262+
```
263+
264+
Then restart gitea and open a STL file on your gitea instance.
265+
183266
## Customizing Gitea mails
184267

185268
The `custom/templates/mail` folder allows changing the body of every mail of Gitea.

0 commit comments

Comments
 (0)