Skip to content

Commit

Permalink
Color blocks on homepage by rarity (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
terror committed Aug 18, 2022
1 parent d6a2f79 commit 1ca529e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
#[derive(Display)]
pub(crate) struct HomeHtml {
last: u64,
hashes: Vec<BlockHash>,
blocks: Vec<(&'static str, BlockHash)>,
}

impl HomeHtml {
Expand All @@ -14,7 +14,10 @@ impl HomeHtml {
.map(|(height, _)| height)
.cloned()
.unwrap_or(0),
hashes: blocks.into_iter().map(|(_, hash)| hash).collect(),
blocks: blocks
.into_iter()
.map(|(height, hash)| (Height(height).starting_ordinal().rarity(), hash))
.collect(),
}
}
}
Expand Down Expand Up @@ -50,8 +53,8 @@ mod tests {
<nav>.*</nav>
<h2>Recent Blocks</h2>
<ol start=1 reversed>
<li><a href=/block/1{64}>1{64}</a></li>
<li><a href=/block/0{64}>0{64}</a></li>
<li><a href=/block/1{64} class=uncommon>1{64}</a></li>
<li><a href=/block/0{64} class=mythic>0{64}</a></li>
</ol>
",
&HomeHtml::new(vec![
Expand Down
1 change: 0 additions & 1 deletion static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ span.legendary {

span.mythic {
background-color: #f2a900;
color: white;
}

a.common {
Expand Down
4 changes: 2 additions & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1>Ordinals</h1>
</nav>
<h2>Recent Blocks</h2>
<ol start={{self.last}} reversed>
%% for hash in &self.hashes {
<li><a href=/block/{{hash}}>{{hash}}</a></li>
%% for (rarity, hash) in &self.blocks {
<li><a href=/block/{{hash}} class={{rarity}}>{{hash}}</a></li>
%% }
</ol>
6 changes: 3 additions & 3 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ fn home() {
<nav>.*</nav>
<h2>Recent Blocks</h2>
<ol start=1 reversed>
<li><a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>
<li><a href=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/block/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206>0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206</a></li>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=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/block/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 class=mythic>0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206</a></li>
</ol>.*",
);
}
Expand All @@ -218,7 +218,7 @@ fn home_block_limit() {
state.request_regex(
"/",
200,
".*<ol start=200 reversed>\n( <li><a href=/block/[[:xdigit:]]{64}>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
".*<ol start=200 reversed>\n( <li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
);
}

Expand Down

0 comments on commit 1ca529e

Please sign in to comment.