Skip to content

Commit

Permalink
Display more information homepage (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 4, 2022
1 parent 5c83e42 commit 7d9385e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,12 @@ mod tests {
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
.*
<h2>Recent Blocks</h2>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>0</dd>
<dt>epoch</dt><dd>0</dd>
<dt>period</dt><dd>0</dd>
</dl>
<ol start=1 reversed class='blocks monospace'>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f class=mythic>000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</a></li>
Expand Down
19 changes: 14 additions & 5 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use super::*;
pub(crate) struct HomeHtml {
last: u64,
blocks: Vec<(Rarity, BlockHash)>,
starting_ordinal: Option<Ordinal>,
}

impl HomeHtml {
pub(crate) fn new(blocks: Vec<(u64, BlockHash)>) -> Self {
Self {
starting_ordinal: blocks
.get(0)
.map(|(height, _)| Height(*height).starting_ordinal()),
last: blocks
.get(0)
.map(|(height, _)| height)
Expand Down Expand Up @@ -37,13 +41,13 @@ mod tests {
assert_regex_match!(
&HomeHtml::new(vec![
(
1,
1260001,
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap()
),
(
0,
1260000,
"0000000000000000000000000000000000000000000000000000000000000000"
.parse()
.unwrap()
Expand All @@ -54,10 +58,15 @@ mod tests {
<nav>.*</nav>
<h2>Search</h2>
<form action=/search method=get>.*</form>
<h2>Recent Blocks</h2>
<ol start=1 reversed class='blocks monospace'>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>1</dd>
<dt>epoch</dt><dd>6</dd>
<dt>period</dt><dd>625</dd>
</dl>
<ol start=1260001 reversed class='blocks monospace'>
<li><a href=/block/1{64} class=uncommon>1{64}</a></li>
<li><a href=/block/0{64} class=mythic>0{64}</a></li>
<li><a href=/block/0{64} class=legendary>0{64}</a></li>
</ol>
",
);
Expand Down
9 changes: 8 additions & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ <h2>Search</h2>
<input autocapitalize=off autocomplete=off autocorrect=off autofocus name=query spellcheck=false type=text>
<input type=submit>
</form>
<h2>Recent Blocks</h2>
<h2>Latest Blocks</h2>
%% if let Some(starting_ordinal) = self.starting_ordinal {
<dl>
<dt>cycle</dt><dd>{{starting_ordinal.cycle()}}</dd>
<dt>epoch</dt><dd>{{starting_ordinal.epoch()}}</dd>
<dt>period</dt><dd>{{starting_ordinal.period()}}</dd>
</dl>
%% }
<ol start={{self.last}} reversed class='blocks monospace'>
%% for (rarity, hash) in &self.blocks {
<li><a href=/block/{{hash}} class={{rarity}}>{{hash}}</a></li>
Expand Down

0 comments on commit 7d9385e

Please sign in to comment.