Skip to content

Commit

Permalink
Use <ol> for homepage (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Aug 18, 2022
1 parent ad0f641 commit 1558046
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Server {

async fn home(index: extract::Extension<Arc<Index>>) -> impl IntoResponse {
match index.blocks(100) {
Ok(blocks) => HomeHtml { blocks }.page().into_response(),
Ok(blocks) => HomeHtml::new(blocks).page().into_response(),
Err(err) => {
eprintln!("Error getting blocks: {err}");
(
Expand Down
54 changes: 36 additions & 18 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@ use super::*;

#[derive(Display)]
pub(crate) struct HomeHtml {
pub(crate) blocks: Vec<(u64, BlockHash)>,
last: u64,
hashes: Vec<BlockHash>,
}

impl HomeHtml {
pub(crate) fn new(blocks: Vec<(u64, BlockHash)>) -> Self {
Self {
last: blocks
.get(0)
.map(|(height, _)| height)
.cloned()
.unwrap_or(0),
hashes: blocks.into_iter().map(|(_, hash)| hash).collect(),
}
}
}

impl Content for HomeHtml {
Expand Down Expand Up @@ -32,25 +46,29 @@ mod tests {
#[test]
fn home_html() {
assert_regex_match!(
"<h1>Ordinals</h1>
"<h1>Ordinals</h1>
<nav>.*</nav>
<h2>Recent Blocks</h2>
<ul>
<li>1 - <a href=/block/1111111111111111111111111111111111111111111111111111111111111111>1111111111111111111111111111111111111111111111111111111111111111</a></li>
<li>0 - <a href=/block/0000000000000000000000000000000000000000000000000000000000000000>0000000000000000000000000000000000000000000000000000000000000000</a></li>
</ul>
<ol start=1 reversed>
<li><a href=/block/1{64}>1{64}</a></li>
<li><a href=/block/0{64}>0{64}</a></li>
</ol>
",
&HomeHtml {
blocks: vec![
(
1,
"1111111111111111111111111111111111111111111111111111111111111111".parse().unwrap()
),
(
0,
"0000000000000000000000000000000000000000000000000000000000000000".parse().unwrap()
)
],
}.to_string());
&HomeHtml::new(vec![
(
1,
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap()
),
(
0,
"0000000000000000000000000000000000000000000000000000000000000000"
.parse()
.unwrap()
)
],)
.to_string()
);
}
}
8 changes: 4 additions & 4 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ <h1>Ordinals</h1>
<a href=https://discord.gg/87cjuz4FYg>Discord</a>
</nav>
<h2>Recent Blocks</h2>
<ul>
%% for block in &self.blocks {
<li>{{block.0}} - <a href=/block/{{block.1}}>{{block.1}}</a></li>
<ol start={{self.last}} reversed>
%% for hash in &self.hashes {
<li><a href=/block/{{hash}}>{{hash}}</a></li>
%% }
</ul>
</ol>
10 changes: 5 additions & 5 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ fn home() {
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
<h2>Recent Blocks</h2>
<ul>
<li>1 - <a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>
<li>0 - <a href=/block/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206>0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206</a></li>
</ul>.*",
<ol start=1 reversed>
<li><a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>
<li><a href=/block/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206>0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206</a></li>
</ol>.*",
);
}

Expand All @@ -175,7 +175,7 @@ fn home_block_limit() {
state.request_regex(
"/",
200,
".*<ul>\n( <li>[[:digit:]]{3} - <a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>\n){100}</ul>.*"
".*<ol start=200 reversed>\n( <li><a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
);
}

Expand Down

0 comments on commit 1558046

Please sign in to comment.