Skip to content

Commit

Permalink
multilanguage sites
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Sep 6, 2024
1 parent b87c852 commit ec927ab
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).

## [0.11.0] - Unreleased
### Added
- Support for multilanguage sites.

## [0.10.1] - 2024-08-30
### Fixed
- Updated dependencies.
Expand Down Expand Up @@ -157,6 +161,7 @@ First version
[#8]: https://github.com/lumeland/theme-simple-wiki/issues/8
[#9]: https://github.com/lumeland/theme-simple-wiki/issues/9

[0.11.0]: https://github.com/lumeland/theme-simple-wiki/compare/v0.10.1...HEAD
[0.10.1]: https://github.com/lumeland/theme-simple-wiki/compare/v0.10.0...v0.10.1
[0.10.0]: https://github.com/lumeland/theme-simple-wiki/compare/v0.9.3...v0.10.0
[0.9.3]: https://github.com/lumeland/theme-simple-wiki/compare/v0.9.2...v0.9.3
Expand Down
6 changes: 4 additions & 2 deletions _config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import lume from "lume/mod.ts";
import notes from "./mod.ts";
import theme from "./mod.ts";
import ogimages from "lume/plugins/og_images.ts";
import metas from "lume/plugins/metas.ts";

const site = lume({
src: "./src",
});

site.use(notes());
site.use(theme({
languages: ["en", "gl"],
}));
site.use(ogimages());
site.use(metas());

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"lume/": "https://deno.land/x/[email protected]/",
"lume/cms/": "https://cdn.jsdelivr.net/gh/lumeland/cms@0.5.10/"
"lume/cms/": "https://cdn.jsdelivr.net/gh/lumeland/cms@v0.5.10/"
},
"lock": false,
"tasks": {
Expand Down
20 changes: 19 additions & 1 deletion plugins.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { merge } from "lume/core/utils/object.ts";
import postcss from "lume/plugins/postcss.ts";
import pagefind from "lume/plugins/pagefind.ts";
import resolveUrls from "lume/plugins/resolve_urls.ts";
Expand All @@ -13,6 +14,7 @@ import phosphor, {
Options as IconOptions,
} from "https://deno.land/x/[email protected]/phosphor.ts";
import { alert } from "npm:@mdit/[email protected]";
import multilanguage from "lume/plugins/multilanguage.ts";

import "lume/types.ts";

Expand All @@ -26,9 +28,20 @@ export interface Options {
* Options for the phosphor plugin.
*/
icons?: IconOptions;

/**
* Language options for the multilanguage plugin.
* The first language is the default language.
*/
languages?: string[];
}
export const defaults: Options = {
languages: ["en"],
};

export default function (userOptions?: Options) {
const options = merge(defaults, userOptions);

export default function (options: Options = {}) {
return (site: Lume.Site) => {
site.use(nav())
.use(title())
Expand All @@ -41,6 +54,11 @@ export default function (options: Options = {}) {
.use(date())
.use(favicon(options.favicon))
.use(basePath())
.data("languages", options.languages)
.use(multilanguage({
languages: options.languages,
defaultLanguage: options.languages[0],
}))
.use(phosphor({
...options.icons,
name: "icon",
Expand Down
22 changes: 22 additions & 0 deletions src/_includes/css/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@
margin-right: 1rem;
}
}
.menu-languages {
list-style: none;
margin: 0 0 1rem 0;
padding: 0;
display: flex;
gap: .5em;
text-transform: uppercase;
font: var(--font-small);

a {
color: var(--color-dim);
display: block;
border-radius: .3em;
padding: .25em;

&[aria-current="page"] {
text-decoration: none;
color: var(--color-base);
background-color: var(--color-line);
}
}
}

.menu {
display: block;
Expand Down
14 changes: 13 additions & 1 deletion src/_includes/templates/menu.vto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
{{ /if }}
{{ /if }}

<tree-menu class="menu" data-url="{{ '/menu.json' |> url }}"></tree-menu>
{{ if alternates.length > 1 }}
<ul class="menu-languages">
{{ for alt of alternates }}
<li>
<a href="{{ alt.url }}" {{ if alt.lang == lang }}aria-current="page"{{ /if }} title="{{ alt.title |> escape }}">
{{ alt.lang }}
</a>
</li>
{{ /for }}
</ul>
{{ /if }}

<tree-menu class="menu" data-url="{{ `/menu-${lang}.json` |> url }}"></tree-menu>

{{- for link of menu_links }}
<li>
Expand Down
1 change: 1 addition & 0 deletions src/gl/_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lang: gl
7 changes: 7 additions & 0 deletions src/gl/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
id: index
---

# Simple Wiki

crea arquivos markdown para engadir páxinas.
4 changes: 4 additions & 0 deletions src/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
id: index
---

# Simple Wiki

Create markdown files to add pages.
12 changes: 9 additions & 3 deletions src/menu.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export const url = "/menu.json";

export default function ({ nav }: Lume.Data) {
const menu = nav.menu("/", "", "order=asc basename=asc").children;
export default function* ({ nav, languages }: Lume.Data) {
for (const lang of languages) {
const menu =
nav.menu("/", `lang=${lang}`, "order=asc basename=asc").children;

return JSON.stringify(menu, null, 2);
yield {
url: `/menu-${lang}.json`,
content: JSON.stringify(menu, null, 2),
};
}
}
4 changes: 4 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
> * {
grid-column: 2;
}

&:has(.menu-languages) {
grid-template-rows: auto auto minmax(0, 1fr);
}
}
}
.container > .toolbar {
Expand Down

0 comments on commit ec927ab

Please sign in to comment.