display date
This commit is contained in:
parent
e9668a65d8
commit
45aa090cf3
7 changed files with 42 additions and 19 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -11,11 +11,18 @@ dependencies = [
|
|||
"readformat",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
|
||||
|
||||
[[package]]
|
||||
name = "plank"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"horrorhttp",
|
||||
"humantime",
|
||||
"readformat",
|
||||
"urlencoding",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
horrorhttp = "0.2.5"
|
||||
humantime = "2.3.0"
|
||||
readformat = "1.0.4"
|
||||
urlencoding = "2.1.3"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ title: holds the post title
|
|||
max-width: min(70vw, max(50vw, 900px));
|
||||
background-color: #202030;
|
||||
display: block;
|
||||
padding: 0 5px 5px 5px;
|
||||
padding: 5px;
|
||||
border: 1px solid #808080;
|
||||
}
|
||||
|
||||
|
|
@ -60,10 +60,9 @@ title: holds the post title
|
|||
display: block;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
h6 {
|
||||
margin: 0;
|
||||
padding-top: 5px;
|
||||
|
||||
span.date {
|
||||
font-size: 0.8em;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,9 @@ pub fn parents(login: Option<Account>, child: Post, reply_on_gid: &str) -> Strin
|
|||
parents(login.clone(), p.clone(), reply_on_gid)
|
||||
+ &prep(POST)
|
||||
.replace("POSTID", &p.get_gid())
|
||||
.replace("AUTHOR", p.get_author())
|
||||
.replace("DATE", &p.get_date_string())
|
||||
.replace("SAFETITLE", &p.get_title().replace("\"", "''"))
|
||||
.replace("AUTHOR", p.get_author())
|
||||
.replace(
|
||||
"TITLE",
|
||||
&p.get_title()
|
||||
|
|
@ -102,8 +103,9 @@ pub fn post(login: Option<Account>, template: &str, p: Post, reply_on_gid: &str)
|
|||
let replymode = reply_on_gid == p.get_gid() && login.is_some();
|
||||
prep(template)
|
||||
.replace("POSTID", &p.get_gid())
|
||||
.replace("AUTHOR", p.get_author())
|
||||
.replace("DATE", &p.get_date_string())
|
||||
.replace("SAFETITLE", &p.get_title().replace("\"", "''"))
|
||||
.replace("AUTHOR", p.get_author())
|
||||
.replace(
|
||||
"TITLE",
|
||||
&p.get_title()
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@
|
|||
-->
|
||||
<post id="POSTID">
|
||||
<div class=content>
|
||||
<h3> AUTHOR: <a href="/post/POSTID#POSTID">TITLE</a> </h3>
|
||||
<span class=date>DATE</span>
|
||||
<h3> AUTHOR: <a href="/post/POSTID#POSTID">TITLE</a> </h3>
|
||||
|
||||
CONTENT
|
||||
CONTENT
|
||||
|
||||
<div class=controls>
|
||||
REPLYBTN
|
||||
</div>
|
||||
<div class=controls>
|
||||
REPLYBTN
|
||||
</div>
|
||||
</div>
|
||||
|
||||
EDITSCREEN
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@
|
|||
-->
|
||||
<post id="POSTID">
|
||||
<a href="/post/POSTID"><div class="content preview">
|
||||
AUTHOR:
|
||||
<b class=title> TITLE </b>
|
||||
<span class=date style="font-size: 0.5em">DATE</span>
|
||||
AUTHOR:
|
||||
<b class=title> TITLE </b>
|
||||
</div></a>
|
||||
</post>
|
||||
|
||||
|
|
|
|||
22
src/post.rs
22
src/post.rs
|
|
@ -3,6 +3,7 @@ use std::{
|
|||
os::unix::fs::symlink,
|
||||
path::{Path, PathBuf},
|
||||
sync::{LazyLock, OnceLock},
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -49,6 +50,21 @@ impl Post {
|
|||
Post::get_by_gid(&self.get_property("PARENT"))
|
||||
}
|
||||
|
||||
pub fn get_date_string(&self) -> String {
|
||||
humantime::format_rfc3339_seconds(self.get_date())
|
||||
.to_string()
|
||||
.replace("T", " ")
|
||||
.replace("Z", " UTC")
|
||||
}
|
||||
|
||||
pub fn get_date(&self) -> SystemTime {
|
||||
SystemTime::UNIX_EPOCH + Duration::from_millis(self.id.parse().unwrap_or(0))
|
||||
}
|
||||
|
||||
pub fn get_date_millis(&self) -> u128 {
|
||||
self.id.parse().unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn get_title(&self) -> String {
|
||||
self.get_property("TITLE")
|
||||
}
|
||||
|
|
@ -96,11 +112,7 @@ pub fn read_replies(replypath: PathBuf) -> Vec<Post> {
|
|||
})
|
||||
})
|
||||
.collect();
|
||||
posts.sort_unstable_by(|a, b| {
|
||||
a.id.parse()
|
||||
.unwrap_or(0u128)
|
||||
.cmp(&b.id.parse().unwrap_or(0u128))
|
||||
});
|
||||
posts.sort_unstable_by(|a, b| a.get_date_millis().cmp(&b.get_date_millis()));
|
||||
posts
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue