Skip to content

Commit

Permalink
feat?: Add basepath for sub-directory of domains
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 23, 2024
1 parent 1cee78e commit a3916b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# atsphinx.mini18n
mini18n_default_language = "ja"
mini18n_support_languages = ["en", "ja"]
mini18n_basepath = "/mini18n/"


def setup(app):
Expand Down
2 changes: 2 additions & 0 deletions src/atsphinx/mini18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def autocomplete_config(app: Sphinx, config: Config):
if not config.html_context:
config.html_context = {}
config.html_context["mini18n"] = {
"basepath": config.mini18n_basepath,
"support_languages": config.mini18n_support_languages,
}

Expand All @@ -101,6 +102,7 @@ def setup(app: Sphinx): # noqa: D103
register_i18n_builders(app)
app.add_config_value("mini18n_default_language", None, "env")
app.add_config_value("mini18n_support_languages", [], "env")
app.add_config_value("mini18n_basepath", "/", "env")
app.connect("config-inited", autocomplete_config)
return {
"version": __version__,
Expand Down
9 changes: 6 additions & 3 deletions src/atsphinx/mini18n/templates/mini18n/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
<body>
<script>
const url = new URL(window.location.href);
if (["/", "/index.html"].includes(url.pathname)) {
// TODO: Set default lauguage
url.pathname = "/{{ config.mini18n_default_language }}/";
const targets = [
'{{ config.mini18n_basepath }}',
'{{ config.mini18n_basepath }}/index.html',
];
if (targets.includes(url.pathname)) {
url.pathname = '{{ config.mini18n_basepath }}{{ config.mini18n_default_language }}/';
location.href = url.href;
}
</script>
Expand Down

0 comments on commit a3916b2

Please sign in to comment.