diff --git a/assets/script.js b/assets/script.js index 7932394..aa9f0db 100644 --- a/assets/script.js +++ b/assets/script.js @@ -259,6 +259,22 @@ function openEditor() { } } +function initializeTheme() { + const form = document.getElementById('article-editor'); + + let preSelectedTheme = form.querySelector(`.theme-picker--option[checked]`); + if (preSelectedTheme) return; + + let themes = form.querySelectorAll(`.theme-picker--option`); + let randomThemeId = (Math.random() * themes.length) | 0; + + let theme = themes[randomThemeId]; + theme.defaultChecked = theme.checked = true; + document.querySelector("body").className = `theme-${theme.value}`; +} + +initializeTheme(); + document .getElementById("openEditor") .addEventListener("click", function (ev) { diff --git a/src/resources/new_article_resource.rs b/src/resources/new_article_resource.rs index 1e96923..40f2fb0 100644 --- a/src/resources/new_article_resource.rs +++ b/src/resources/new_article_resource.rs @@ -87,15 +87,13 @@ impl Resource for NewArticleResource { let title = self.slug.as_ref() .map_or("".to_owned(), |x| title_from_slug(x)); - let theme = theme::theme_from_str_hash(&title); - Box::new(self.head() .and_then(move |head| { Ok(head .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: &title, - theme, + theme: theme::Theme::Gray, body: &Template { revision: NEW, last_updated: None, @@ -106,7 +104,7 @@ impl Resource for NewArticleResource { rendered: EMPTY_ARTICLE_MESSAGE, themes: &theme::THEMES.iter().map(|&x| SelectableTheme { theme: x, - selected: x == theme, + selected: false, }).collect::>(), }, }.to_string()))