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