Skip to content

Commit

Permalink
[themes] only apply grid layout to pages generated using the default …
Browse files Browse the repository at this point in the history
…Page::body_html, fixes #1272
  • Loading branch information
shish committed Sep 9, 2024
1 parent fa2d171 commit 59227b1
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 34 deletions.
33 changes: 20 additions & 13 deletions core/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,34 +572,40 @@ public function render(): void
);
}

public function html_html(HTMLElement $head, string|HTMLElement $body): HTMLElement
public function html_html(HTMLElement $head, HTMLElement $body): HTMLElement
{
global $user;

$body_attrs = [
"data-userclass" => $user->class->name,
"data-base-href" => get_base_href(),
"data-base-link" => make_link(""),
];

return emptyHTML(
rawHTML("<!doctype html>"),
HTML(
["lang" => "en"],
HEAD($head),
BODY($body_attrs, $body)
$head,
$body,
)
);
}

protected function head_html(): HTMLElement
{
return emptyHTML(
return HEAD(
TITLE($this->title),
$this->get_all_html_headers(),
);
}

/**
* @return array<string, string>
*/
public function body_attrs(string $class): array
{
global $user;
return [
"class" => $class,
"data-userclass" => $user->class->name,
"data-base-href" => get_base_href(),
"data-base-link" => make_link(""),
];
}

protected function body_html(): HTMLElement
{
$left_block_html = [];
Expand All @@ -625,7 +631,8 @@ protected function body_html(): HTMLElement

$footer_html = $this->footer_html();
$flash_html = $this->flash_html();
return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HTML_HEADER(
H1($this->heading),
...$sub_block_html
Expand Down
2 changes: 1 addition & 1 deletion ext/ext_manager/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function display_table(Page $page, array $extensions, bool $editable): vo

$cat_html = [
A(["href" => make_link()], "Index"),
BR(),
" ",
];
foreach ($categories as $cat) {
$cat_html[] = A(["href" => "#".$cat->value], $cat->value);
Expand Down
4 changes: 1 addition & 3 deletions ext/home/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ public function onPageRequest(PageRequestEvent $event): void
{
global $config, $page;
if ($event->page_matches("home")) {
$base_href = get_base_href();
$sitename = $config->get_string(SetupConfig::TITLE);
$theme_name = $config->get_string(SetupConfig::THEME);

$body = $this->get_body();

$this->theme->display_page($page, $sitename, $base_href, $theme_name, $body);
$this->theme->display_page($page, $sitename, $body);
}
}

Expand Down
13 changes: 9 additions & 4 deletions ext/home/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{emptyHTML, TITLE, META, rawHTML};
use function MicroHTML\{BODY, emptyHTML, TITLE, META, rawHTML};

class HomeTheme extends Themelet
{
public function display_page(Page $page, string $sitename, string $base_href, string $theme_name, HTMLElement $body): void
public function display_page(Page $page, string $sitename, HTMLElement $body): void
{
$page->set_mode(PageMode::DATA);
$page->add_auto_html_headers();
Expand All @@ -28,6 +28,8 @@ public function display_page(Page $page, string $sitename, string $base_href, st

public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, string $num_comma, string $counter_text): HTMLElement
{
global $page;

$main_links_html = empty($main_links) ? "" : "<div class='space' id='links'>$main_links</div>";
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='space' id='counter'>$counter_text</div>";
Expand All @@ -41,7 +43,9 @@ public function build_body(string $sitename, string $main_links, string $main_te
</form>
</div>
";
return rawHTML("
return BODY(
$page->body_attrs("home"),
rawHTML("
<div id='front-page'>
<h1><a style='text-decoration: none;' href='".make_link()."'><span>$sitename</span></a></h1>
$main_links_html
Expand All @@ -54,6 +58,7 @@ public function build_body(string $sitename, string $main_links, string $main_te
Running <a href='https://code.shishnet.org/shimmie2/'>Shimmie2</a>
</small></small>
</div>
</div>");
</div>")
);
}
}
5 changes: 3 additions & 2 deletions themes/danbooru/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV};
use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV};

/**
* Name: Danbooru Theme
Expand Down Expand Up @@ -121,7 +121,8 @@ public function body_html(): HTMLElement
$flash_html = $this->flash_html();
$footer_html = $this->footer_html();

return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HEADER(
$title_link,
UL(["id" => "navbar", "class" => "flat-list"], $custom_links),
Expand Down
5 changes: 3 additions & 2 deletions themes/danbooru2/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV};
use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV};

/**
* Name: Danbooru 2 Theme
Expand Down Expand Up @@ -122,7 +122,8 @@ public function body_html(): HTMLElement
$flash_html = $this->flash_html();
$footer_html = $this->footer_html();

return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HEADER(
$title_link,
UL(["id" => "navbar", "class" => "flat-list"], $custom_links),
Expand Down
8 changes: 5 additions & 3 deletions themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ HEADER H1 {
overflow: hidden;
}
BODY {
display: grid;
grid-template-columns: 216px auto;
grid-gap: 0 10px;
background: var(--page);
color: var(--text);
margin: 0;
}
BODY.grid {
display: grid;
grid-template-columns: 216px auto;
grid-gap: 0 10px;
}
H1 {
background: var(--title);
border: 1px solid var(--title-border);
Expand Down
5 changes: 3 additions & 2 deletions themes/futaba/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, HR, HEADER, H1, NAV};
use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, HR, HEADER, H1, NAV};

class FutabaPage extends Page
{
Expand Down Expand Up @@ -48,7 +48,8 @@ public function body_html(): HTMLElement
$flash_html = $this->flash_html();
$footer_html = $this->footer_html();

return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HEADER(
H1($this->heading),
$subheading,
Expand Down
5 changes: 3 additions & 2 deletions themes/lite/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{emptyHTML, HEADER, FOOTER, DIV, SCRIPT, A, B, IMG, NAV, ARTICLE, rawHTML, SECTION};
use function MicroHTML\{BODY, emptyHTML, HEADER, FOOTER, DIV, SCRIPT, A, B, IMG, NAV, ARTICLE, rawHTML, SECTION};

/**
* Name: Lite Theme
Expand Down Expand Up @@ -94,7 +94,8 @@ public function body_html(): HTMLElement

$footer_html = $this->footer_html();

return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HEADER(
$menu,
$custom_sublinks,
Expand Down
5 changes: 3 additions & 2 deletions themes/warm/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use MicroHTML\HTMLElement;

use function MicroHTML\{A, TABLE, TR, TD, SMALL, rawHTML, emptyHTML, DIV, ARTICLE, FOOTER, HEADER, H1, NAV};
use function MicroHTML\{BODY, A, TABLE, TR, TD, SMALL, rawHTML, emptyHTML, DIV, ARTICLE, FOOTER, HEADER, H1, NAV};

class WarmPage extends Page
{
Expand Down Expand Up @@ -46,7 +46,8 @@ public function body_html(): HTMLElement
$flash_html = $this->flash_html();
$footer_html = $this->footer_html();

return emptyHTML(
return BODY(
$this->body_attrs("grid"),
HEADER(
DIV(
["style" => "text-align: center;"],
Expand Down

0 comments on commit 59227b1

Please sign in to comment.