Skip to content

Commit

Permalink
Add Layout to WikitextSettings.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Jul 15, 2024
1 parent e9b78d3 commit 8d1085c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/render/html/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use super::random::Random;
use crate::data::PageRef;
use crate::data::{Backlinks, PageInfo};
use crate::info;
use crate::layout::Layout;
use crate::next_index::{NextIndex, TableOfContentsIndex};
use crate::render::Handle;
use crate::settings::WikitextSettings;
Expand Down Expand Up @@ -109,7 +110,7 @@ impl<'i, 'h, 'e, 't> HtmlContext<'i, 'h, 'e, 't> {
// Build and return
HtmlContext {
body: String::with_capacity(capacity),
meta: Self::initial_metadata(info),
meta: Self::initial_metadata(info, settings.layout),
backlinks: Backlinks::new(),
info,
handle,
Expand All @@ -127,7 +128,7 @@ impl<'i, 'h, 'e, 't> HtmlContext<'i, 'h, 'e, 't> {
}
}

fn initial_metadata(info: &PageInfo<'i>) -> Vec<HtmlMeta> {
fn initial_metadata(info: &PageInfo<'i>, layout: Layout) -> Vec<HtmlMeta> {
// Initial version, we can tune how the metadata is generated later.

vec![
Expand All @@ -139,7 +140,7 @@ impl<'i, 'h, 'e, 't> HtmlContext<'i, 'h, 'e, 't> {
HtmlMeta {
tag_type: HtmlMetaType::Name,
name: str!("generator"),
value: info::VERSION.clone(),
value: format!("{} {}", *info::VERSION, layout.description()),
},
HtmlMeta {
tag_type: HtmlMetaType::Name,
Expand Down
13 changes: 12 additions & 1 deletion src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

mod interwiki;

use crate::layout::Layout;

pub use self::interwiki::{InterwikiSettings, DEFAULT_INTERWIKI, EMPTY_INTERWIKI};

const DEFAULT_MINIFY_CSS: bool = true;
Expand All @@ -31,6 +33,11 @@ pub struct WikitextSettings {
/// What mode we're running in.
pub mode: WikitextMode,

/// What layout we're targeting.
///
/// For instance, generating Wikidot's legacy HTML structure.
pub layout: Layout,

/// Whether page-contextual syntax is permitted.
///
/// This currently refers to:
Expand Down Expand Up @@ -94,12 +101,13 @@ pub struct WikitextSettings {

impl WikitextSettings {
/// Returns the default settings for the given [`WikitextMode`].
pub fn from_mode(mode: WikitextMode) -> Self {
pub fn from_mode(mode: WikitextMode, layout: Layout,) -> Self {
let interwiki = DEFAULT_INTERWIKI.clone();

match mode {
WikitextMode::Page => WikitextSettings {
mode,
layout,
enable_page_syntax: true,
use_include_compatibility: false,
use_true_ids: true,
Expand All @@ -110,6 +118,7 @@ impl WikitextSettings {
},
WikitextMode::Draft => WikitextSettings {
mode,
layout,
enable_page_syntax: true,
use_include_compatibility: false,
use_true_ids: false,
Expand All @@ -120,6 +129,7 @@ impl WikitextSettings {
},
WikitextMode::ForumPost | WikitextMode::DirectMessage => WikitextSettings {
mode,
layout,
enable_page_syntax: false,
use_include_compatibility: false,
use_true_ids: false,
Expand All @@ -130,6 +140,7 @@ impl WikitextSettings {
},
WikitextMode::List => WikitextSettings {
mode,
layout,
enable_page_syntax: true,
use_include_compatibility: false,
use_true_ids: false,
Expand Down

0 comments on commit 8d1085c

Please sign in to comment.