posts are now actually sorted
This commit is contained in:
parent
dad45a965c
commit
c53994d846
12
flake.lock
12
flake.lock
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1738546358,
|
||||
"narHash": "sha256-nLivjIygCiqLp5QcL7l56Tca/elVqM9FG1hGd9ZSsrg=",
|
||||
"lastModified": 1742889210,
|
||||
"narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c6e957d81b96751a3d5967a0fd73694f303cc914",
|
||||
"rev": "698214a32beb4f4c8e3942372c694f40848b360d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -29,11 +29,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1738635966,
|
||||
"narHash": "sha256-5MbJhh6nz7tx8FYVOJ0+ixMaEn0ibGzV/hScPMmqVTE=",
|
||||
"lastModified": 1743129211,
|
||||
"narHash": "sha256-gE8t+U9miTwm2NYWS9dFY8H1/QB4ifaFDq1KdV9KEqo=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "1ff8663cd75a11e61f8046c62f4dbb05d1907b44",
|
||||
"rev": "f93da1d26ba9963f34f94a6872b67a7939699543",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -70,16 +70,18 @@
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
img.enlarged {
|
||||
#enlarged-image {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
height: 80%;
|
||||
max-width: 90%;
|
||||
object-fit: contain;
|
||||
border-radius: 0px;
|
||||
background: transparent;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: var(--background-text)50;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#enlarged-image.visible {
|
||||
display: initial;
|
||||
}
|
||||
|
||||
#content>.footer {
|
||||
|
|
68
src/main.rs
68
src/main.rs
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
env::current_dir,
|
||||
ffi::OsStr,
|
||||
fs::{self, read, DirEntry},
|
||||
fs::{self, DirEntry, read},
|
||||
io::{self, BufRead, BufReader, Read, Write},
|
||||
net::{TcpListener, TcpStream},
|
||||
path::PathBuf,
|
||||
|
@ -125,13 +125,16 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
.filter(|x| {
|
||||
let file_name = x.file_name();
|
||||
let y = file_name.to_str();
|
||||
let ft = x.file_type();
|
||||
if y.is_some() {
|
||||
if y.unwrap().ends_with(".html") {
|
||||
false
|
||||
if ft.is_ok() && ft.unwrap().is_dir() {
|
||||
true
|
||||
} else if y.unwrap().starts_with("_") {
|
||||
false
|
||||
} else {
|
||||
} else if y.unwrap().ends_with(".md") {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
true
|
||||
|
@ -139,18 +142,28 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
})
|
||||
.collect::<Vec<DirEntry>>();
|
||||
entries.sort_by(|a, b| {
|
||||
let mut a = if let Ok(a) = fs::File::open(a.path()) {
|
||||
a
|
||||
} else {
|
||||
eprintln!("{a:?} {b:?}");
|
||||
let path = if a.file_type().unwrap().is_dir() {
|
||||
let mut path = a.path().clone();
|
||||
path.push("post.md");
|
||||
if let Ok(a) = fs::File::open(path) {
|
||||
a
|
||||
} else {
|
||||
return std::cmp::Ordering::Equal;
|
||||
}
|
||||
path
|
||||
} else {
|
||||
a.path().clone()
|
||||
};
|
||||
let mut b = if let Ok(b) = fs::File::open(b.path()) {
|
||||
let mut a = if let Ok(a) = fs::File::open(path) {
|
||||
a
|
||||
} else {
|
||||
eprintln!("Error when opening a, returning equal");
|
||||
return std::cmp::Ordering::Equal;
|
||||
};
|
||||
let path = if b.file_type().unwrap().is_dir() {
|
||||
let mut path = b.path().clone();
|
||||
path.push("post.md");
|
||||
path
|
||||
} else {
|
||||
b.path().clone()
|
||||
};
|
||||
let mut b = if let Ok(b) = fs::File::open(path) {
|
||||
b
|
||||
} else {
|
||||
let mut path = b.path().clone();
|
||||
|
@ -158,9 +171,11 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
if let Ok(b) = fs::File::open(path) {
|
||||
b
|
||||
} else {
|
||||
eprintln!("Error when opening b, returning equal");
|
||||
return std::cmp::Ordering::Equal;
|
||||
}
|
||||
};
|
||||
eprintln!("{a:?} {b:?}");
|
||||
|
||||
let mut buf: &mut [u8] = &mut [0; 16];
|
||||
let _ = a.read(&mut buf);
|
||||
|
@ -171,6 +186,8 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
let _ = b.read(&mut *buf);
|
||||
let b = String::from_utf8_lossy(buf);
|
||||
|
||||
println!("{a} {b}");
|
||||
|
||||
let a = if let Ok(a) = a
|
||||
.chars()
|
||||
.take_while(|x| x != &'\n')
|
||||
|
@ -179,6 +196,7 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
{
|
||||
a
|
||||
} else {
|
||||
eprintln!("Error when reading a, returning equal");
|
||||
return std::cmp::Ordering::Equal;
|
||||
};
|
||||
|
||||
|
@ -190,6 +208,7 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
{
|
||||
b
|
||||
} else {
|
||||
eprintln!("Error when reading b, returning equal");
|
||||
return std::cmp::Ordering::Equal;
|
||||
};
|
||||
|
||||
|
@ -240,14 +259,21 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
get_mime_type(path.extension())
|
||||
)
|
||||
}
|
||||
Err(e) =>
|
||||
match e.kind() {
|
||||
io::ErrorKind::NotFound => format!("HTTP/1.1 404\r\n\r\n{:?} not found", req.get_path().unwrap()),
|
||||
io::ErrorKind::PermissionDenied => format!("HTTP/1.1 403\r\n\r\n{:?} not readable", req.get_path().unwrap()),
|
||||
io::ErrorKind::FileTooLarge => format!("HTTP/1.1 413\r\n\r\n{:?} was too large", req.get_path().unwrap()),
|
||||
_ => format!("HTTP/1.1 500{0}{0}{e}", CLRF),
|
||||
}
|
||||
|
||||
Err(e) => match e.kind() {
|
||||
io::ErrorKind::NotFound => format!(
|
||||
"HTTP/1.1 404\r\n\r\n{:?} not found",
|
||||
req.get_path().unwrap()
|
||||
),
|
||||
io::ErrorKind::PermissionDenied => format!(
|
||||
"HTTP/1.1 403\r\n\r\n{:?} not readable",
|
||||
req.get_path().unwrap()
|
||||
),
|
||||
io::ErrorKind::FileTooLarge => format!(
|
||||
"HTTP/1.1 413\r\n\r\n{:?} was too large",
|
||||
req.get_path().unwrap()
|
||||
),
|
||||
_ => format!("HTTP/1.1 500{0}{0}{e}", CLRF),
|
||||
},
|
||||
},
|
||||
None => format!("HTTP/1.1 404{0}{0}", CLRF),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue