stuff
parent
349f24b76f
commit
b3cf350d3f
@ -0,0 +1,3 @@
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]
|
@ -0,0 +1,53 @@
|
||||
const oldOnloadHandler = window.onload ?? (() => {});
|
||||
|
||||
async function historyLoad() {
|
||||
const historyDiv = document.getElementById("story-list");
|
||||
historyDiv.textContent = "";
|
||||
|
||||
const readingHistory = JSON.parse(
|
||||
localStorage.getItem("readingHistory") ?? "[]"
|
||||
);
|
||||
|
||||
for (let i = 0; i < readingHistory.length; i++) {
|
||||
const story = await (
|
||||
await fetch(`/api/getStory?id=${readingHistory[i]}`)
|
||||
).json();
|
||||
|
||||
const searchEle = document.createElement("a");
|
||||
searchEle.className = "story";
|
||||
searchEle.href =
|
||||
"/story?id=" +
|
||||
story.id +
|
||||
(localStorage.getItem(`${story.id}_progress`)
|
||||
? `&chapter=${localStorage.getItem(`${story.id}_progress`)}`
|
||||
: "");
|
||||
const coverEle = document.createElement("img");
|
||||
coverEle.src = story.cover;
|
||||
const div = document.createElement("div");
|
||||
const titleEle = document.createElement("h3");
|
||||
titleEle.textContent = story.title;
|
||||
div.appendChild(titleEle);
|
||||
const descEle = document.createElement("p");
|
||||
descEle.innerHTML = story.description.replace("\n", "<br/>");
|
||||
div.appendChild(descEle);
|
||||
searchEle.appendChild(coverEle);
|
||||
searchEle.appendChild(div);
|
||||
historyDiv?.appendChild(searchEle);
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = async () => {
|
||||
oldOnloadHandler();
|
||||
|
||||
// render history
|
||||
await historyLoad();
|
||||
|
||||
/* // clear history button
|
||||
const button = document.getElementById("clear-button");
|
||||
|
||||
button.onclick = async () => {
|
||||
localStorage.removeItem("readingHistory");
|
||||
// rerender history
|
||||
await historyLoad();
|
||||
}; */
|
||||
};
|
@ -0,0 +1,60 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cached_wattpad::*;
|
||||
use crate::components::header::{Header, HeaderLink};
|
||||
use crate::WATTPAD;
|
||||
use axum::extract::{Extension, Query, State as AxumState};
|
||||
use maud::{html, Markup, PreEscaped, DOCTYPE};
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
|
||||
pub async fn render() -> Markup {
|
||||
html! {
|
||||
(DOCTYPE)
|
||||
title {"Home | Voltpad"};
|
||||
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
||||
style {(PreEscaped(
|
||||
grass::include!("./css/index.scss")
|
||||
))}
|
||||
script {(PreEscaped(
|
||||
include_str!("../../scripts/History.js")
|
||||
))}
|
||||
(
|
||||
Header(vec![
|
||||
HeaderLink {
|
||||
name: "Home".to_string(),
|
||||
path: "/".to_string(),
|
||||
prefix: None,
|
||||
postfix: None
|
||||
},
|
||||
HeaderLink {
|
||||
name: "Search".to_string(),
|
||||
path: "/search".to_string(),
|
||||
prefix: None,
|
||||
postfix: None
|
||||
},
|
||||
HeaderLink {
|
||||
name: "History".to_string(),
|
||||
path: "/history".to_string(),
|
||||
prefix: None,
|
||||
postfix: None
|
||||
},
|
||||
HeaderLink {
|
||||
name: "About".to_string(),
|
||||
path: "/about".to_string(),
|
||||
prefix: None,
|
||||
postfix: None
|
||||
},
|
||||
], "/history".to_string())
|
||||
)
|
||||
div .index-content {
|
||||
h1 { "History" }
|
||||
noscript {
|
||||
h3 {
|
||||
"This won't work without JS. Run off now, GNU LibreJS looking motherfuckers."
|
||||
}
|
||||
}
|
||||
div .story-list #story-list;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod history;
|
||||
pub mod index;
|
||||
pub mod not_found;
|
||||
pub mod story;
|
||||
|
@ -0,0 +1,17 @@
|
||||
use crate::cached_wattpad::get_story as get_story_from_wattpad;
|
||||
use axum::extract::{Json, Query};
|
||||
use serde::Deserialize;
|
||||
use wattpad::Story;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GetStoryParams {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
pub async fn get_story(Query(params): Query<GetStoryParams>) -> Json<Story> {
|
||||
let story = get_story_from_wattpad(¶ms.id)
|
||||
.await
|
||||
.expect("idk jump off a bridge");
|
||||
|
||||
Json(story)
|
||||
}
|
Loading…
Reference in new issue