! Bulk commit of progression
A lot off issues with the current design make 100% more sense by cutting hugo out of the picture entirely This means we're switching fully to rocket however we're not going to leave behind the work done with hugo, we're just going to migrate it over first
This commit is contained in:
parent
de4b44ac90
commit
4b6ced439d
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ api/vids/
|
||||
frontend/themes/clippable/static/js/index.js
|
||||
frontend/public/
|
||||
frontend/themes/clippable/static/js/category.js
|
||||
frontend/themes/clippable/static/js/collection.js
|
||||
|
@ -12,6 +12,6 @@ fn main() {
|
||||
* CLIP_DIR
|
||||
*/
|
||||
let _ = rocket::ignite()
|
||||
.mount("/api", routes![video::list_categories])
|
||||
.mount("/api", routes![video::list_categories, video::list_videos])
|
||||
.launch();
|
||||
}
|
||||
|
@ -13,6 +13,13 @@ struct Category {
|
||||
thumbnail: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Video {
|
||||
name: String,
|
||||
category: String,
|
||||
thumbnail: Option<String>
|
||||
}
|
||||
|
||||
fn get_nail(dirpath: &Path) -> std::io::Result<Option<String>> {
|
||||
let mut t_path = dirpath.to_path_buf(); t_path.push(".thumbnail.jpg");
|
||||
|
||||
@ -29,7 +36,7 @@ fn get_nail(dirpath: &Path) -> std::io::Result<Option<String>> {
|
||||
pub fn list_categories() -> JsonValue {
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(e) => "/media/clips/".to_string()
|
||||
Err(_) => "/media/clips/".to_string()
|
||||
};
|
||||
|
||||
// Fucking hell this is going to be dumb
|
||||
@ -48,3 +55,24 @@ pub fn list_categories() -> JsonValue {
|
||||
|
||||
json!({"categories": cats})
|
||||
}
|
||||
|
||||
#[get("/category/<cat>")]
|
||||
pub fn list_videos(cat: String) -> JsonValue {
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(_) => "/media/clips".to_string()
|
||||
};
|
||||
|
||||
let mut vids: Vec<Video> = Vec::new();
|
||||
for file in fs::read_dir(dir).unwrap() {
|
||||
match file {
|
||||
Ok(file) => {
|
||||
let name = file.file_name()
|
||||
.into_string().unwrap_or(String::new());
|
||||
vids.push(Video {name, category: cat.clone(), thumbnail: None})
|
||||
},
|
||||
_ => continue
|
||||
}
|
||||
}
|
||||
return json!({"videos": vids})
|
||||
}
|
6
frontend/content/collection.md
Normal file
6
frontend/content/collection.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
title: Shockrah's Clips
|
||||
description: stay a while and watch
|
||||
image: /favicon.png
|
||||
type: collection
|
||||
---
|
15
frontend/themes/clippable/layouts/collection/baseof.html
Normal file
15
frontend/themes/clippable/layouts/collection/baseof.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
{{- partial "head.html" . -}}
|
||||
<script src="/js/collection.js"></script>
|
||||
<body>
|
||||
<div id="layout">
|
||||
<div class="content">
|
||||
{{- block "main" . -}}{{- end -}}
|
||||
<div class="video-gallery" id="main-container">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
4
frontend/themes/clippable/layouts/collection/single.html
Normal file
4
frontend/themes/clippable/layouts/collection/single.html
Normal file
@ -0,0 +1,4 @@
|
||||
{{ define "main" }}
|
||||
{{ .Content }}
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
{{ end }}
|
@ -34,6 +34,10 @@ html, body, div, tag {
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
a {
|
||||
color:white;
|
||||
}
|
||||
|
||||
.pure-form {
|
||||
text-align: center;
|
||||
}
|
||||
|
59
frontend/ts/collection.ts
Normal file
59
frontend/ts/collection.ts
Normal file
@ -0,0 +1,59 @@
|
||||
// This module takes care of pulling down videos for the given category
|
||||
class Video {
|
||||
title: string
|
||||
category: string
|
||||
thumbnail_b64: string|null
|
||||
constructor(raw: any) {
|
||||
this.title = raw['name']
|
||||
this.category = raw['category']
|
||||
this.thumbnail_b64 = raw['thumbnail']
|
||||
}
|
||||
|
||||
title_link() : HTMLHeadingElement {
|
||||
let container = document.createElement('h2')
|
||||
|
||||
let link = document.createElement('a')
|
||||
link.href = `/video?c=${this.category}&v=${this.title}`
|
||||
link.text = this.title
|
||||
|
||||
container.appendChild(link)
|
||||
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
function get_category() : string|null {
|
||||
// Used to modify the DOM
|
||||
let params = (new URL(document.location.toString())).searchParams;
|
||||
return params.get('c')
|
||||
}
|
||||
function base_url() : string {
|
||||
const loc = document.location
|
||||
return loc.protocol + '//' + loc.host
|
||||
}
|
||||
|
||||
function fetch_videos() : Array<Video> {
|
||||
const category = get_category()
|
||||
if(!category) { return [] }
|
||||
const endpoint = base_url() + `/api/categories?c=${category}`
|
||||
|
||||
let xml = new XMLHttpRequest()
|
||||
xml.open('GET', endpoint, false) // sync request
|
||||
xml.send(null) // no params required
|
||||
if(xml.getResponseHeader('Content-Type') == 'application/json') {
|
||||
let raw = JSON.parse(xml.responseText)
|
||||
for(const vid of raw['videos']) {
|
||||
console.log(vid)
|
||||
}
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
function ready(e) {
|
||||
if(document.readyState != 'complete') { return e }
|
||||
|
||||
const video_data = fetch_videos()
|
||||
}
|
||||
|
||||
document.addEventListener('readystatechange', ready)
|
@ -6,13 +6,19 @@ class Category {
|
||||
this.thumbnail_b64 = raw['thumbnail']
|
||||
}
|
||||
|
||||
public as_div_str() {
|
||||
let container = document.createElement('div')
|
||||
container.className = 'video-block'
|
||||
title_link() : HTMLHeadingElement {
|
||||
let container = document.createElement('h2')
|
||||
|
||||
let title = document.createElement('h2')
|
||||
title.innerText = this.name
|
||||
let link = document.createElement('a')
|
||||
link.href = `/collection?c=${this.name}`
|
||||
link.text = this.name
|
||||
|
||||
container.appendChild(link)
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
thumbnail_div() : HTMLImageElement {
|
||||
let nail = document.createElement('img')
|
||||
nail.className = 'pure-img'
|
||||
|
||||
@ -22,9 +28,19 @@ class Category {
|
||||
nail.setAttribute('src', '/cantfindshit.gif')
|
||||
}
|
||||
|
||||
container.appendChild(title)
|
||||
container.appendChild(nail)
|
||||
return nail
|
||||
}
|
||||
public as_div() {
|
||||
let container = document.createElement('div')
|
||||
container.className = 'video-block'
|
||||
|
||||
let title = this.title_link()
|
||||
let thumbnail = this.thumbnail_div()
|
||||
|
||||
container.appendChild(title)
|
||||
container.appendChild(thumbnail)
|
||||
|
||||
// Dump gallery onto the main page
|
||||
document.getElementById('main-container').appendChild(container)
|
||||
|
||||
return container
|
||||
@ -45,7 +61,7 @@ function ready_handler(e?: Event) : Event {
|
||||
let raw = JSON.parse(xml.responseText)
|
||||
for(const cat_raw of raw['categories']) {
|
||||
let cat = new Category(cat_raw)
|
||||
cat.as_div_str()
|
||||
cat.as_div()
|
||||
}
|
||||
}
|
||||
return e
|
||||
|
Loading…
Reference in New Issue
Block a user