From ec927abee9e3224cb232e3016e9720c85ebace8f Mon Sep 17 00:00:00 2001 From: Oscar Otero Date: Fri, 6 Sep 2024 12:16:35 +0200 Subject: [PATCH] multilanguage sites --- CHANGELOG.md | 5 +++++ _config.ts | 6 ++++-- deno.json | 2 +- plugins.ts | 20 +++++++++++++++++++- src/_includes/css/menu.css | 22 ++++++++++++++++++++++ src/_includes/templates/menu.vto | 14 +++++++++++++- src/gl/_data.yml | 1 + src/gl/index.md | 7 +++++++ src/index.md | 4 ++++ src/menu.page.ts | 12 +++++++++--- src/styles.css | 4 ++++ 11 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/gl/_data.yml create mode 100644 src/gl/index.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 01bcc71..1ccafd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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 diff --git a/_config.ts b/_config.ts index 880d848..76ed572 100644 --- a/_config.ts +++ b/_config.ts @@ -1,5 +1,5 @@ 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"; @@ -7,7 +7,9 @@ const site = lume({ src: "./src", }); -site.use(notes()); +site.use(theme({ + languages: ["en", "gl"], +})); site.use(ogimages()); site.use(metas()); diff --git a/deno.json b/deno.json index 592ce78..ce81f85 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "imports": { "lume/": "https://deno.land/x/lume@v2.3.0/", - "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": { diff --git a/plugins.ts b/plugins.ts index 4c727dd..967f509 100644 --- a/plugins.ts +++ b/plugins.ts @@ -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"; @@ -13,6 +14,7 @@ import phosphor, { Options as IconOptions, } from "https://deno.land/x/lume_icon_plugins@v0.2.3/phosphor.ts"; import { alert } from "npm:@mdit/plugin-alert@0.13.1"; +import multilanguage from "lume/plugins/multilanguage.ts"; import "lume/types.ts"; @@ -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()) @@ -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", diff --git a/src/_includes/css/menu.css b/src/_includes/css/menu.css index e0578df..71bd793 100644 --- a/src/_includes/css/menu.css +++ b/src/_includes/css/menu.css @@ -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; diff --git a/src/_includes/templates/menu.vto b/src/_includes/templates/menu.vto index 0ef5c3e..f27c24e 100644 --- a/src/_includes/templates/menu.vto +++ b/src/_includes/templates/menu.vto @@ -9,7 +9,19 @@ {{ /if }} {{ /if }} - + {{ if alternates.length > 1 }} + + {{ /if }} + + {{- for link of menu_links }}
  • diff --git a/src/gl/_data.yml b/src/gl/_data.yml new file mode 100644 index 0000000..72905ff --- /dev/null +++ b/src/gl/_data.yml @@ -0,0 +1 @@ +lang: gl \ No newline at end of file diff --git a/src/gl/index.md b/src/gl/index.md new file mode 100644 index 0000000..e95a798 --- /dev/null +++ b/src/gl/index.md @@ -0,0 +1,7 @@ +--- +id: index +--- + +# Simple Wiki + +crea arquivos markdown para engadir páxinas. diff --git a/src/index.md b/src/index.md index 754a052..9cff689 100644 --- a/src/index.md +++ b/src/index.md @@ -1,3 +1,7 @@ +--- +id: index +--- + # Simple Wiki Create markdown files to add pages. diff --git a/src/menu.page.ts b/src/menu.page.ts index a732ae9..36cac16 100644 --- a/src/menu.page.ts +++ b/src/menu.page.ts @@ -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), + }; + } } diff --git a/src/styles.css b/src/styles.css index cf4dd32..9ce66aa 100644 --- a/src/styles.css +++ b/src/styles.css @@ -72,6 +72,10 @@ > * { grid-column: 2; } + + &:has(.menu-languages) { + grid-template-rows: auto auto minmax(0, 1fr); + } } } .container > .toolbar {