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

add preview image for inscription page #1010

Merged
merged 6 commits into from
Dec 19, 2022
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
4 changes: 4 additions & 0 deletions src/subcommand/server/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub(crate) trait PageContent: Display + 'static {
{
PageHtml::new(self, chain, has_satoshi_index)
}

fn preview_image_url(&self) -> Option<Trusted<String>> {
None
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand/server/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl PageContent for InscriptionHtml {
fn title(&self) -> String {
format!("Inscription {}", self.inscription_id)
}

fn preview_image_url(&self) -> Option<Trusted<String>> {
Some(Trusted(format!("/content/{}", self.inscription_id)))
}
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset=utf-8>
<meta name=format-detection content='telephone=no'>
<meta name=viewport content='width=device-width,initial-scale=1.0'>
%% if let Some(url) = self.content.preview_image_url() {
<meta property=og:image content='{{ url }}'>
%% }
<title>{{ self.content.title() }}</title>
<link href=/static/index.css rel=stylesheet>
<link href=/static/modern-normalize.css rel=stylesheet>
Expand Down
3 changes: 2 additions & 1 deletion tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ fn inscription_page() {
TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex(
&format!("/inscription/{reveal_tx}"),
&format!(
".*<h1>Inscription {reveal_tx}</h1>
".*<meta property=og:image content='/content/{reveal_tx}'>.*
<h1>Inscription {reveal_tx}</h1>
<dl>
<dt>content size</dt>
<dd>10 bytes</dd>
Expand Down