Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thumbnail links #1199

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod tests {
)
.to_string(),
"<h2>Latest Inscriptions</h2>
<div class=inscriptions>
<div class=thumbnails>
<a href=/inscription/1{64}><iframe .* src=/preview/1{64}></iframe></a>
<a href=/inscription/2{64}><iframe .* src=/preview/2{64}></iframe></a>
</div>
Expand Down
16 changes: 8 additions & 8 deletions src/templates/iframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ use super::*;

pub(crate) struct Iframe {
inscription_id: InscriptionId,
main: bool,
thumbnail: bool,
}

impl Iframe {
pub(crate) fn preview(inscription_id: InscriptionId) -> Trusted<Self> {
pub(crate) fn thumbnail(inscription_id: InscriptionId) -> Trusted<Self> {
Trusted(Self {
inscription_id,
main: false,
thumbnail: true,
})
}

pub(crate) fn main(inscription_id: InscriptionId) -> Trusted<Self> {
Trusted(Self {
inscription_id,
main: true,
thumbnail: false,
})
}
}

impl Display for Iframe {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if self.main {
if self.thumbnail {
write!(
f,
"<a href=/preview/{}><iframe sandbox=allow-scripts scrolling=no src=/preview/{}></iframe></a>",
"<a href=/inscription/{}><iframe sandbox=allow-scripts scrolling=no src=/preview/{}></iframe></a>",
self.inscription_id,
self.inscription_id,
)
} else {
write!(
f,
"<a href=/inscription/{}><iframe sandbox=allow-scripts scrolling=no src=/preview/{}></iframe></a>",
"<a href=/preview/{}><iframe sandbox=allow-scripts scrolling=no src=/preview/{}></iframe></a>",
self.inscription_id,
self.inscription_id,
)
Expand All @@ -48,7 +48,7 @@ mod tests {
#[test]
fn preview() {
assert_regex_match!(
Iframe::preview(txid(1))
Iframe::thumbnail(txid(1))
.0.to_string(),
"<a href=/inscription/1{64}><iframe sandbox=allow-scripts scrolling=no src=/preview/1{64}></iframe></a>",
);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
},
"
<h1>Inscriptions</h1>
<div class=inscriptions>
<div class=thumbnails>
<a href=/inscription/1{64}><iframe .* src=/preview/1{64}></iframe></a>
<a href=/inscription/2{64}><iframe .* src=/preview/2{64}></iframe></a>
</div>
Expand Down
31 changes: 31 additions & 0 deletions src/templates/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,35 @@ mod tests {
.unindent()
);
}

#[test]
fn with_inscriptions() {
assert_regex_match!(
OutputHtml {
inscriptions: vec![txid(1)],
outpoint: "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0"
.parse()
.unwrap(),
list: None,
chain: Chain::Mainnet,
output: TxOut {
value: 3,
script_pubkey: Script::new_p2pkh(&PubkeyHash::all_zeros()),
},
},
"
<h1>Output <span class=monospace>4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</span></h1>
<dl>
<dt>inscriptions</dt>
<dd class=thumbnails>
<a href=/inscription/1{64}><iframe .* src=/preview/1{64}></iframe></a>
</dd>
<dt>value</dt><dd>3</dd>
<dt>script pubkey</dt><dd class=data>OP_DUP OP_HASH160 OP_PUSHBYTES_20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG</dd>
<dt>address</dt><dd class=monospace>1111111111111111111114oLvT2</dd>
</dl>
"
.unindent()
);
}
}
8 changes: 2 additions & 6 deletions src/templates/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ mod tests {
sat: Sat(0),
satpoint: None,
blocktime: Blocktime::Confirmed(0),
inscription: Some(
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap(),
),
inscription: Some(txid(1)),
},
r"<h1>Sat 0</h1>.*<dt>inscription</dt><dd><a href=/inscription/1{64}>.*</a></dd>.*",
r"<h1>Sat 0</h1>.*<dt>inscription</dt><dd class=thumbnails><a href=/inscription/1{64}>.*</a></dd>.*",
);
}

Expand Down
6 changes: 3 additions & 3 deletions static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,19 @@ a.mythic {
color: var(--mythic);
}

.inscriptions {
.thumbnails {
display: flex;
flex-wrap: wrap;
}

.inscriptions > a {
.thumbnails > a {
border-radius: 2%;
margin: 1%;
overflow: hidden;
width: 23%;
}

.inscriptions iframe {
.thumbnails iframe {
height: 101%;
overflow: hidden;
width: 101%;
Expand Down
4 changes: 2 additions & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% if !&self.inscriptions.is_empty() {
<h2>Latest Inscriptions</h2>
<div class=inscriptions>
<div class=thumbnails>
%% for id in &self.inscriptions {
{{Iframe::preview(*id)}}
{{Iframe::thumbnail(*id)}}
%% }
</div>
<div class=center><a href=/inscriptions>more…</a></div>
Expand Down
4 changes: 2 additions & 2 deletions templates/inscriptions.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Inscriptions</h1>
<div class=inscriptions>
<div class=thumbnails>
%% for id in &self.inscriptions {
{{Iframe::preview(*id)}}
{{Iframe::thumbnail(*id)}}
%% }
</div>
4 changes: 3 additions & 1 deletion templates/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ <h1>Output <span class=monospace>{{self.outpoint}}</span></h1>
<dl>
%% if !self.inscriptions.is_empty() {
<dt>inscriptions</dt>
<dd class=thumbnails>
%% for inscription in &self.inscriptions {
<dd>{{Iframe::preview(*inscription)}}</dd>
{{Iframe::thumbnail(*inscription)}}
%% }
</dd>
%% }
<dt>value</dt><dd>{{ self.output.value }}</dd>
<dt>script pubkey</dt><dd class=data>{{ self.output.script_pubkey.asm() }}</dd>
Expand Down
2 changes: 1 addition & 1 deletion templates/sat.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Sat {{ self.sat.n() }}</h1>
<dt>rarity</dt><dd><span class={{self.sat.rarity()}}>{{ self.sat.rarity() }}</span></dd>
<dt>time</dt><dd>{{ self.blocktime }}</dd>
%% if let Some((inscription)) = &self.inscription {
<dt>inscription</dt><dd>{{ Iframe::preview(*inscription) }}</dd>
<dt>inscription</dt><dd class=thumbnails>{{ Iframe::thumbnail(*inscription) }}</dd>
%% }
%% if let Some(satpoint) = self.satpoint {
<dt>location</dt><dd class=monospace>{{ satpoint }}</dd>
Expand Down
4 changes: 3 additions & 1 deletion templates/transaction.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<h1>Transaction <span class=monospace>{{self.txid}}</span></h1>
%% if let Some(inscription) = &self.inscription {
<h2>Inscription Geneses</h2>
{{ Iframe::preview(self.txid) }}
<div class=thumbnails>
{{ Iframe::thumbnail(self.txid) }}
</div>
%% }
<h2>{{"Output".tally(self.transaction.output.len())}}</h2>
<ul class=monospace>
Expand Down
6 changes: 3 additions & 3 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn home_page_includes_latest_inscriptions() {
"/",
format!(
".*<h2>Latest Inscriptions</h2>
<div class=inscriptions>
<div class=thumbnails>
<a href=/inscription/{inscription_id}><iframe .*></a>
</div>.*"
),
Expand All @@ -239,7 +239,7 @@ fn home_page_inscriptions_are_sorted() {
"/",
format!(
".*<h2>Latest Inscriptions</h2>
<div class=inscriptions>{inscriptions}
<div class=thumbnails>{inscriptions}
</div>.*"
),
);
Expand All @@ -266,7 +266,7 @@ fn inscriptions_page() {
"/inscriptions",
format!(
".*<h1>Inscriptions</h1>
<div class=inscriptions>
<div class=thumbnails>
<a href=/inscription/{reveal_tx}>.*</a>
</div>
.*",
Expand Down