From 48f8d732acbdc6491e80335028630907e4467236 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 17 Aug 2022 21:04:14 -0700 Subject: [PATCH 1/3] Use an ordered list for homepage --- src/subcommand/server.rs | 2 +- src/subcommand/server/templates/home.rs | 54 ++++++++++++++++--------- templates/home.html | 8 ++-- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index c73d026de3..fc8f711b73 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -243,7 +243,7 @@ impl Server { async fn home(index: extract::Extension>) -> 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}"); ( diff --git a/src/subcommand/server/templates/home.rs b/src/subcommand/server/templates/home.rs index 4f23f1da93..4b040f76ae 100644 --- a/src/subcommand/server/templates/home.rs +++ b/src/subcommand/server/templates/home.rs @@ -2,7 +2,21 @@ use super::*; #[derive(Display)] pub(crate) struct HomeHtml { - pub(crate) blocks: Vec<(u64, BlockHash)>, + last: u64, + hashes: Vec, +} + +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 { @@ -32,25 +46,29 @@ mod tests { #[test] fn home_html() { assert_regex_match!( -"

Ordinals

+ "

Ordinals

Recent Blocks

- +
    +
  1. 1{64}
  2. +
  3. 0{64}
  4. +
", - &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() + ); } } diff --git a/templates/home.html b/templates/home.html index afc215fa7b..ee8691de19 100644 --- a/templates/home.html +++ b/templates/home.html @@ -8,8 +8,8 @@

Ordinals

Discord

Recent Blocks

-
    -%% for block in &self.blocks { -
  • {{block.0}} - {{block.1}}
  • +
      +%% for hash in &self.hashes { +
    1. {{hash}}
    2. %% } -
+ From 498f25bd4674896248fa8afb9f4fee3fac76a23a Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 17 Aug 2022 21:05:13 -0700 Subject: [PATCH 2/3] Switch up order --- src/subcommand/server/templates/home.rs | 2 +- templates/home.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subcommand/server/templates/home.rs b/src/subcommand/server/templates/home.rs index 4b040f76ae..ba3246c458 100644 --- a/src/subcommand/server/templates/home.rs +++ b/src/subcommand/server/templates/home.rs @@ -49,7 +49,7 @@ mod tests { "

Ordinals

Recent Blocks

-
    +
    1. 1{64}
    2. 0{64}
    diff --git a/templates/home.html b/templates/home.html index ee8691de19..600d82b601 100644 --- a/templates/home.html +++ b/templates/home.html @@ -8,7 +8,7 @@

    Ordinals

    Discord

    Recent Blocks

    -
      +
        %% for hash in &self.hashes {
      1. {{hash}}
      2. %% } From 83ddf90ac2e355906e63e0d66903b76ba3c9b118 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 17 Aug 2022 21:07:49 -0700 Subject: [PATCH 3/3] fix-tests --- tests/server.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/server.rs b/tests/server.rs index 79b12edb75..c0236c1b01 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -159,10 +159,10 @@ fn home() { ".*Ordinals.*

        Ordinals

        Recent Blocks

        -.*", +
          +
        1. [[:xdigit:]]{64}
        2. +
        3. 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
        4. +
        .*", ); } @@ -175,7 +175,7 @@ fn home_block_limit() { state.request_regex( "/", 200, - ".*.*" + ".*
          \n(
        1. [[:xdigit:]]{64}
        2. \n){100}
        .*" ); }