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

Serve same favicon regardless of browser #3003

Merged
merged 2 commits into from
Jan 12, 2024
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
83 changes: 42 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,56 +261,57 @@ Release x.y.z
Translations
------------

To translate [the docs](https://docs.ordinals.com) we use this
To translate [the docs](https://docs.ordinals.com) we use
[mdBook i18n helper](https://github.com/google/mdbook-i18n-helpers).
So read through their [usage guide](https://github.com/google/mdbook-i18n-helpers/blob/main/i18n-helpers/USAGE.md)
to see the structure that translations should follow.

There are some other things to watch out for but feel free to just start a
translation and open a PR. Have a look at [this commit](https://github.com/ordinals/ord/commit/329f31bf6dac207dad001507dd6f18c87fdef355)
for an idea of what to do. A maintainer will also help you integrate it into our
build system.
See
[mdbook-i18n-helpers usage guide](https://github.com/google/mdbook-i18n-helpers/blob/main/i18n-helpers/USAGE.md)
for help.

To align your translated version of the Handbook with reference to commit
[#2427](https://github.com/ordinals/ord/pull/2426), here are some guiding
commands to assist you. It is assumed that your local environment is already
well-configured with [Python](https://www.python.org/),
[Mdbook](https://github.com/rust-lang/mdBook),
[mdBook i18n helper](https://github.com/google/mdbook-i18n-helpers) and that you've clone
this repo.
Adding a new translations is somewhat involved, so feel free to start
translation and open a pull request, even if your translation is incomplete.

Take a look at
[this commit](https://github.com/ordinals/ord/commit/329f31bf6dac207dad001507dd6f18c87fdef355)
for an example of adding a new translation. A maintainer will help you integrate it
into our build system.

1. Run the following command to generate a new `pot` file, which is named as
`messages.pot`:
To start a new translation:

```
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}'
mdbook build -d po
```
1. Install `mdbook`, `mdbook-i18n-helpers`, and `mdbook-linkcheck`:

2. Run `msgmerge` where `xx.po` is your localized language version following
the naming standard of [ISO639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
This process will update the `po` file with the most recent original version:
```
cargo install mdbook mdbook-i18n-helpers mdbook-linkcheck
```

```
msgmerge --update po/xx.po po/messages.pot
```
2. Generate a new `pot` file named `messages.pot`:

3. Look for `#, fuzzy`. The `mdBook-i18n-helper` tool utilizes the `"fuzzy"` tag
to highlight sections that have been recently edited. You can proceed to perform
the translation tasks by editing the `"fuzzy"`part.
```
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}'
mdbook build -d po
```

4. Execute the `mdbook` command. A demonstration in Chinese (`zh`) is given below:
3. Run `msgmerge` on `XX.po` where `XX` is the two-letter
[ISO-639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code for
the language you are translating into. This will update the `po` file with
the text of the most recent English version:

```
mdbook build docs -d build
MDBOOK_BOOK__LANGUAGE=zh mdbook build docs -d build/zh
mv docs/build/zh/html docs/build/html/zh
python3 -m http.server --directory docs/build/html --bind 127.0.0.1 8080
```
```
msgmerge --update po/XX.po po/messages.pot
```

4. Untranslated sections are marked with `#, fuzzy` in `XX.po`. Edit the
`msgstr` string with the translated text.

5. Execute the `mdbook` command to rebuild the docs. For Chinese, whose
two-letter ISO-639 code is `zh`:

```
mdbook build docs -d build
MDBOOK_BOOK__LANGUAGE=zh mdbook build docs -d build/zh
mv docs/build/zh/html docs/build/html/zh
python3 -m http.server --directory docs/build/html --bind 127.0.0.1 8080
```

5. Upon verifying everything and ensuring all is in order, you can commit the
modifications and progress to open a Pull Request (PR) on Github.
(**Note**: Please ensure **ONLY** the **'xx.po'** file is pushed, other files
such as '.pot' or files ending in '~' are **unnecessary** and should **NOT** be
included in the Pull Request.)
6. If everything looks good, commit `XX.po` and open a pull request on GitHub.
Other changed files should be omitted from the pull request.
1 change: 1 addition & 0 deletions docs/theme/favicon.png
1 change: 1 addition & 0 deletions docs/theme/favicon.svg
4 changes: 3 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ flamegraph dir=`git branch --show-current`:
./bin/flamegraph $1

serve-docs: build-docs
open http://127.0.0.1:8080
python3 -m http.server --directory docs/build/html --bind 127.0.0.1 8080

open-docs:
open http://127.0.0.1:8080

build-docs:
#!/usr/bin/env bash
mdbook build docs -d build
Expand Down
35 changes: 7 additions & 28 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use {
axum::{
body,
extract::{Extension, Json, Path, Query},
headers::UserAgent,
http::{header, HeaderMap, HeaderValue, StatusCode, Uri},
response::{IntoResponse, Redirect, Response},
routing::get,
Router, TypedHeader,
Router,
},
axum_server::Handle,
brotli::Decompressor,
Expand Down Expand Up @@ -880,32 +879,12 @@ impl Server {
})
}

async fn favicon(user_agent: Option<TypedHeader<UserAgent>>) -> ServerResult<Response> {
if user_agent
.map(|user_agent| {
user_agent.as_str().contains("Safari/")
&& !user_agent.as_str().contains("Chrome/")
&& !user_agent.as_str().contains("Chromium/")
})
.unwrap_or_default()
{
Ok(
Self::static_asset(Path("/favicon.png".to_string()))
.await
.into_response(),
)
} else {
Ok(
(
[(
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'unsafe-inline'"),
)],
Self::static_asset(Path("/favicon.svg".to_string())).await?,
)
.into_response(),
)
}
async fn favicon() -> ServerResult<Response> {
Ok(
Self::static_asset(Path("/favicon.png".to_string()))
.await
.into_response(),
)
}

async fn feed(
Expand Down
4 changes: 3 additions & 1 deletion src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ mod tests {
<meta property=og:image content='https://signet.ordinals.com/static/favicon.png'>
<meta property=twitter:card content=summary>
<title>Foo</title>
<link rel=alternate href=/feed.xml type=application/rss\+xml title='Inscription RSS Feed'>
<link rel=alternate href=/feed.xml type=application/rss\+xml title='Inscription Feed'>
<link rel=icon href=/static/favicon.png>
<link rel=icon href=/static/favicon.svg>
<link rel=stylesheet href=/static/index.css>
<link rel=stylesheet href=/static/modern-normalize.css>
<script src=/static/index.js defer></script>
Expand Down
6 changes: 2 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ macro_rules! assert_regex_match {
let string = $value.to_string();

if !regex.is_match(string.as_ref()) {
panic!(
"Regex:\n\n{}\n\n…did not match string:\n\n{}",
regex, string
);
eprintln!("Regex did not match:");
pretty_assert_eq!(regex.as_str(), string);
}
};
}
Expand Down
Binary file modified static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<meta property=og:image content='{{ self.og_image() }}'>
<meta property=twitter:card content=summary>
<title>{{ self.content.title() }}</title>
<link rel=alternate href=/feed.xml type=application/rss+xml title='Inscription RSS Feed'>
<link rel=alternate href=/feed.xml type=application/rss+xml title='Inscription Feed'>
<link rel=icon href=/static/favicon.png>
<link rel=icon href=/static/favicon.svg>
<link rel=stylesheet href=/static/index.css>
<link rel=stylesheet href=/static/modern-normalize.css>
<script src=/static/index.js defer></script>
Expand Down
Loading