Skip to content

Commit

Permalink
Show text inscriptions on the home page
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 23, 2022
1 parent 71ff62d commit 2bd9127
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,6 @@ impl Index {
continue;
};

if !inscription.is_graphical() {
continue;
}

inscriptions.push((inscription, id));

if inscriptions.len() == n {
Expand Down
13 changes: 0 additions & 13 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ impl Inscription {
pub(crate) fn content_type(&self) -> Option<&str> {
str::from_utf8(self.content_type.as_ref()?).ok()
}

pub(crate) fn is_graphical(&self) -> bool {
matches!(self.content(), Some(Content::Image) | Some(Content::IFrame))
}
}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -707,13 +703,4 @@ mod tests {
}
);
}

#[test]
fn is_graphical() {
assert!(inscription("image/png", []).is_graphical());
assert!(!inscription("foo", []).is_graphical());
assert!(inscription("image/gif", []).is_graphical());
assert!(inscription("image/svg+xml", []).is_graphical());
assert!(!Inscription::new(None, Some(Vec::new())).is_graphical());
}
}
4 changes: 2 additions & 2 deletions src/subcommand/server/templates/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {
inscription_id: txid(1),
}
.to_string(),
"<pre>foo</pre>"
"<pre class=inscription>foo</pre>"
);
}

Expand All @@ -66,7 +66,7 @@ mod tests {
inscription_id: txid(1),
}
.to_string(),
"<pre>&lt;script&gt;alert(&apos;hello!&apos;)&lt;/script&gt;</pre>",
"<pre class=inscription>&lt;script&gt;alert(&apos;hello!&apos;)&lt;/script&gt;</pre>",
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tests {
use super::*;

#[test]
fn home_html() {
fn html() {
assert_regex_match!(
&HomeHtml::new(
vec![
Expand All @@ -64,7 +64,7 @@ mod tests {
.to_string(),
"<h1>Bitcoin-native NFTs</h1>.*<h2>Latest Inscriptions</h2>
<div class=inscriptions>
<a href=/inscription/1111111111111111111111111111111111111111111111111111111111111111><pre>HELLOWORLD</pre></a>
<a href=/inscription/1111111111111111111111111111111111111111111111111111111111111111><pre class=inscription>HELLOWORLD</pre></a>
</div>
<h2>Status</h2>
<dl>
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod tests {
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<pre>HELLOWORLD</pre>
<pre class=inscription>HELLOWORLD</pre>
</a>
<dl>
<dt>content size</dt>
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/server/templates/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod tests {
<dt>rarity</dt><dd><span class=mythic>mythic</span></dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>inscription</dt>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre>HELLOWORLD</pre></a></dd>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre class=inscription>HELLOWORLD</pre></a></dd>
</dl>
prev
<a href=/sat/1>next</a>
Expand Down Expand Up @@ -156,7 +156,7 @@ mod tests {
<dt>rarity</dt><dd><span class=mythic>mythic</span></dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>inscription</dt>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre>&lt;script&gt;alert(&apos;HELLOWORLD&apos;);&lt;/script&gt;</pre></a></dd>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre class=inscription>&lt;script&gt;alert(&apos;HELLOWORLD&apos;);&lt;/script&gt;</pre></a></dd>
</dl>
prev
<a href=/sat/1>next</a>
Expand Down
6 changes: 5 additions & 1 deletion static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ a.mythic {
margin: 1%;
overflow: hidden;
border-radius: 2%;
text-decoration: none;
}

.inscriptions img.inscription {
Expand All @@ -183,6 +184,10 @@ a.mythic {
overflow: hidden;
}

.inscriptions pre.inscription {
color: white;
}

.content {
display: flex;
justify-content: center;
Expand All @@ -205,7 +210,6 @@ iframe {

a.content {
color: inherit;
text-decoration: none;
}

img.inscription {
Expand Down
2 changes: 1 addition & 1 deletion tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn inscription_page() {
".*<meta property=og:image content='/content/{reveal_tx}'>.*
<h1>Inscription {reveal_tx}</h1>
<a class=content href=/content/{reveal_tx}>
<pre>HELLOWORLD</pre>
<pre class=inscription>HELLOWORLD</pre>
</a>
<dl>
<dt>content size</dt>
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn inscribe() {

TestServer::spawn_with_args(&rpc_server, &["--index-sats"]).assert_response_regex(
"/sat/5000000000",
".*<dt>inscription</dt>\n <dd>.*<pre>HELLOWORLD</pre>.*</dd>.*",
".*<dt>inscription</dt>\n <dd>.*<pre class=inscription>HELLOWORLD</pre>.*</dd>.*",
);

TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex(
Expand Down

0 comments on commit 2bd9127

Please sign in to comment.