From 65f75c26efcb0ba2533a7ee044f1fc85ea6aa252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 3 Nov 2019 00:06:25 +0100 Subject: [PATCH] AdventOfCode /list view kinda finished --- www/data/css/styles.css | 96 +++++++++++++++++++++ www/data/css/styles.min.css | 13 +++ www/data/css/styles.scss | 1 + www/data/css/styles_blogview_aoc.scss | 120 ++++++++++++++++++++++++++ www/fragments/blogview_aoc_list.php | 62 +++++++++++++ www/index.php | 2 +- www/internals/adventofcode.php | 64 +++++++++++++- www/pages/blog_view.php | 8 +- www/statics/blog/__all.php | 4 +- www/statics/blog/aoc2018.txt | 5 ++ www/statics/blog/aoc2019.txt | 1 + 11 files changed, 367 insertions(+), 9 deletions(-) create mode 100644 www/data/css/styles_blogview_aoc.scss create mode 100644 www/fragments/blogview_aoc_list.php create mode 100644 www/statics/blog/aoc2018.txt create mode 100644 www/statics/blog/aoc2019.txt diff --git a/www/data/css/styles.css b/www/data/css/styles.css index aed6993..f1b26ce 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -1125,6 +1125,102 @@ html, body { flex-direction: row; } } +/* 400px */ +.aoc_calendar_parent { + display: flex; + justify-content: center; + margin-top: 1em; + padding-bottom: 1.5em; +} + +.aoc_calendar_header { + display: flex; + flex-direction: row; + justify-content: space-between; + margin-bottom: 0.5em; + background: #F8B229; +} + +.aoc_calendar_header_link { + display: flex; + color: #000000; + text-decoration: none; +} + +.aoc_calendar_header_title { + flex-grow: 0; + display: flex; + color: #000000; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: bold; +} + +.aoc_calendar_header_link.aoc_prev { + flex-grow: 0; + padding-left: 0.5em; +} + +.aoc_calendar_header_link.aoc_next { + flex-grow: 0; + padding-right: 0.5em; +} + +.aoc_calendar_header_link.aoc_link_hidden { + visibility: hidden; +} + +.aoc_calendar { + display: flex; + flex-direction: column; + background: #EFEFEF; + font-size: xx-large; + font-family: Consolas, Monaco, "Courier New", Menlo, monospace; + border: 1px solid #000000; + padding-bottom: 0.5em; +} + +.aoc_calendar_row { + display: flex; + flex-direction: row; + justify-content: center; + margin-left: 0.5em; + margin-right: 0.5em; +} + +.aoc_calendar_field { + display: flex; + align-items: center; + justify-content: center; + width: 2em; + height: 2em; + margin: 4px; + text-decoration: none; + font-weight: bold; +} + +.aoc_calendar_field.aoc_enabled { + background: #165B33; + color: #BB2528; + border: 1px solid #FFFFFF; + text-shadow: 0 0 0.2em #222; + font-weight: bold; +} + +.aoc_calendar_field.aoc_enabled:hover { + background: #165B00; + color: #BB2528; + border: 1px solid #BB2528; + text-shadow: 0 0 0 #000; +} + +.aoc_calendar_field.aoc_disabled { + background: #444; + color: #888; + border: 1px solid #888; + cursor: default; + font-weight: normal; +} + /* 400px */ .prgl_parent { display: flex; diff --git a/www/data/css/styles.min.css b/www/data/css/styles.min.css index d7c4cf5..f5b31a1 100644 --- a/www/data/css/styles.min.css +++ b/www/data/css/styles.min.css @@ -219,6 +219,19 @@ html,body{margin:0;padding:0;height:100%} .bce_pag10{flex-direction:row} .bce_pag05{flex-direction:row} } +.aoc_calendar_parent{display:flex;justify-content:center;margin-top:1em;padding-bottom:1.5em} +.aoc_calendar_header{display:flex;flex-direction:row;justify-content:space-between;margin-bottom:.5em;background:#f8b229} +.aoc_calendar_header_link{display:flex;color:#000;text-decoration:none} +.aoc_calendar_header_title{flex-grow:0;display:flex;color:#000;font-family:Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:bold} +.aoc_calendar_header_link.aoc_prev{flex-grow:0;padding-left:.5em} +.aoc_calendar_header_link.aoc_next{flex-grow:0;padding-right:.5em} +.aoc_calendar_header_link.aoc_link_hidden{visibility:hidden} +.aoc_calendar{display:flex;flex-direction:column;background:#efefef;font-size:xx-large;font-family:Consolas,Monaco,"Courier New",Menlo,monospace;border:1px solid #000;padding-bottom:.5em} +.aoc_calendar_row{display:flex;flex-direction:row;justify-content:center;margin-left:.5em;margin-right:.5em} +.aoc_calendar_field{display:flex;align-items:center;justify-content:center;width:2em;height:2em;margin:4px;text-decoration:none;font-weight:bold} +.aoc_calendar_field.aoc_enabled{background:#165b33;color:#bb2528;border:1px solid #fff;text-shadow:0 0 .2em #222;font-weight:bold} +.aoc_calendar_field.aoc_enabled:hover{background:#165b00;color:#bb2528;border:1px solid #bb2528;text-shadow:0 0 0 #000} +.aoc_calendar_field.aoc_disabled{background:#444;color:#888;border:1px solid #888;cursor:default;font-weight:normal} .prgl_parent{display:flex;flex-direction:column} @media(max-width:850px){.prgl_parent{align-items:center}} .prgl_elem{display:flex;flex-direction:row;text-decoration:none;background:#BBB;border:solid 1px #444;margin:5px 0} diff --git a/www/data/css/styles.scss b/www/data/css/styles.scss index e0c0921..ab5aeb0 100644 --- a/www/data/css/styles.scss +++ b/www/data/css/styles.scss @@ -10,6 +10,7 @@ @import 'styles_bloglist'; @import 'styles_blogview'; @import 'styles_blogview_euler'; +@import 'styles_blogview_aoc'; @import 'styles_programslist'; @import 'styles_programsview'; diff --git a/www/data/css/styles_blogview_aoc.scss b/www/data/css/styles_blogview_aoc.scss new file mode 100644 index 0000000..4725393 --- /dev/null +++ b/www/data/css/styles_blogview_aoc.scss @@ -0,0 +1,120 @@ +@import 'styles_config'; + +$COL_CHRISTMAS_YELLOW: #F8B229; +$COL_CHRISTMAS_WHITE: #EFEFEF; +$COL_CHRISTMAS_GREEN: #165B33; +$COL_CHRISTMAS_GREEN_ALT: #165B00; +$COL_CHRISTMAS_RED: #BB2528; + +// ==================== AdventOfCode Blog Listing ==================== // + +.aoc_calendar_parent { + display: flex; + justify-content: center; + + margin-top: 1em; + padding-bottom: 1.5em; +} + +.aoc_calendar_header { + display: flex; + flex-direction: row; + justify-content: space-between; + + margin-bottom: 0.5em; + + background: $COL_CHRISTMAS_YELLOW; +} + +.aoc_calendar_header_link { + display: flex; + + color: #000000; + text-decoration: none; +} + +.aoc_calendar_header_title { + flex-grow: 0; + display: flex; + + color: #000000; + font-family: $FONT_HEADER; + font-weight: bold; +} + +.aoc_calendar_header_link.aoc_prev { + flex-grow: 0; + padding-left: 0.5em; +} + +.aoc_calendar_header_link.aoc_next { + flex-grow: 0; + padding-right: 0.5em; +} + +.aoc_calendar_header_link.aoc_link_hidden { + visibility: hidden; +} + +.aoc_calendar { + display: flex; + flex-direction: column; + + background: $COL_CHRISTMAS_WHITE; + + font-size: xx-large; + font-family: $FONT_CODE; + + border: 1px solid #000000; + + padding-bottom: 0.5em; +} + +.aoc_calendar_row { + display: flex; + flex-direction: row; + + justify-content: center; + + margin-left: 0.5em; + margin-right: 0.5em; +} + +.aoc_calendar_field { + display: flex; + align-items: center; + justify-content: center; + + width: 2em; + height: 2em; + + margin: 4px; + + text-decoration: none; + font-weight: bold; +} + +.aoc_calendar_field.aoc_enabled { + background: $COL_CHRISTMAS_GREEN; + color: $COL_CHRISTMAS_RED; + border: 1px solid #FFFFFF; + text-shadow: 0 0 0.2em #222; + font-weight: bold; +} + +.aoc_calendar_field.aoc_enabled:hover { + background: $COL_CHRISTMAS_GREEN_ALT; + color: $COL_CHRISTMAS_RED; + border: 1px solid $COL_CHRISTMAS_RED; + text-shadow: 0 0 0 #000; +} + +.aoc_calendar_field.aoc_disabled { + background: #444; + color: #888; + border: 1px solid #888; + cursor: default; + font-weight: normal; +} + +// ==================== AdventOfCode Blog - Single Day View ==================== // \ No newline at end of file diff --git a/www/fragments/blogview_aoc_list.php b/www/fragments/blogview_aoc_list.php new file mode 100644 index 0000000..0461812 --- /dev/null +++ b/www/fragments/blogview_aoc_list.php @@ -0,0 +1,62 @@ + + +
+ +
+ + Fork me on GitHub + +
+ +
+ +
+ +
+ + + +
+
+
+ <'; + else echo '<'; + + echo ''.$year.''; + + if ($next_year !== null) echo '>'; + else echo '>'; + ?> +
+ + '."\n"; + for ($j=0; $j<5; $j++) + { + $day = $assocdays[$i*5+$j]; + if ($day === null) echo ''.($i*5+$j+1).''."\n"; + else echo ''.($i*5+$j+1).''."\n"; + } + echo '
'."\n"; + } + ?> +
+
+ +
+ \ No newline at end of file diff --git a/www/index.php b/www/index.php index 722ab40..1a10158 100644 --- a/www/index.php +++ b/www/index.php @@ -181,7 +181,7 @@ try { } $OPTIONS = $opt; - include $target; + include $target; return; } diff --git a/www/internals/adventofcode.php b/www/internals/adventofcode.php index 1db47dd..e84d6b3 100644 --- a/www/internals/adventofcode.php +++ b/www/internals/adventofcode.php @@ -10,7 +10,15 @@ class AdventOfCode const LANGUAGES = [ - 'cs' => ['ext'=>'linq', 'css'=>'language-csharp', 'name'=>'C#'], + 'cs' => ['ext'=>'linq', 'css'=>'language-csharp', 'name'=>'C#'], + 'java' => ['ext'=>'java', 'css'=>'language-java', 'name'=>'Java'], + 'bef' => ['ext'=>'b93', 'css'=>'language-befungerunner', 'name'=>'Befunge-93+'], + 'cpp' => ['ext'=>'cpp', 'css'=>'language-cpp', 'name'=>'C++'], + 'pyth' => ['ext'=>'py', 'css'=>'language-python', 'name'=>'Python'], + 'rust' => ['ext'=>'rs', 'css'=>'language-rust', 'name'=>'Rust'], + 'go' => ['ext'=>'go', 'css'=>'language-go', 'name'=>'Go'], + 'js' => ['ext'=>'js', 'css'=>'language-javascript', 'name'=>'Javascript'], + 'pas' => ['ext'=>'pas', 'css'=>'language-pascal', 'name'=>'Pascal/Delphi'], ]; public static function listAllFromAllYears() @@ -26,7 +34,25 @@ class AdventOfCode { $all = require (__DIR__ . '/../statics/aoc/__all.php'); - return array_map('self::readSingle', $all[$year]); + $result = $all[$year]; + + array_walk($result, function(&$value) use ($year) { $value = self::readSingle($year, $value); }); + + return $result; + } + + public static function listSingleYearAssociative($year) + { + $all = self::listSingleYear($year); + + $result = array_fill(0, 25, null); + + foreach ($all as $d) + { + $result[$d['day']-1] = $d; + } + + return $result; } public static function listYears() @@ -85,6 +111,38 @@ class AdventOfCode return null; } + public static function getGithubLink($year) + { + return self::YEARS['' . $year]['github']; + } + + public static function getURLForYear($year) + { + return '/blog/' . self::YEARS[''.$year]['blog-id'] . '/Advent_of_Code_' . $year . '/'; + } + + public static function getPrevYear($year) + { + $last = null; + foreach (self::YEARS as $y => $d) + { + if ($y == $year) return $last; + $last = $y; + } + return null; + } + + public static function getNextYear($year) + { + $found = false; + foreach (self::YEARS as $y => $d) + { + if ($found) return $y; + if ($y == $year) $found = true; + } + return null; + } + public static function checkConsistency() { $warn = null; @@ -104,6 +162,8 @@ class AdventOfCode if (in_array($aocdata['title'], $titlelist)) return ['result'=>'err', 'message' => 'Duplicate title ' . $aocdata['title']]; $titlelist []= $aocdata['title']; + if ($aocdata['day'] < 1 || $aocdata['day'] > 25) return ['result'=>'err', 'message' => 'Invali [day]-value title ' . $aocdata['day']]; + if (count($aocdata['solutions']) !== $aocdata['parts']) return ['result'=>'err', 'message' => 'Not enough solution-values in day' . $aocdata['day']]; if (count($aocdata['file_solutions']) !== $aocdata['parts']) return ['result'=>'err', 'message' => 'Not enough solution-files in day' . $aocdata['day']]; diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index e947462..6de0b2a 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -31,9 +31,9 @@ if ($isSubAdventOfCode) } if ($adventofcodeday === null) $isSubAdventOfCode = false; -$title = $post['title']; -if ($isSubEuler) $title = $eulerproblem['title']; -if ($isSubAdventOfCode) $title = $adventofcodeday['title']; +$htmltitle = $post['title']; +if ($isSubEuler) $htmltitle = $eulerproblem['title']; +if ($isSubAdventOfCode) $htmltitle = $adventofcodeday['title']; $canonical = $post['canonical']; if ($isSubEuler) $canonical = $eulerproblem['canonical']; @@ -42,7 +42,7 @@ if ($isSubAdventOfCode) $canonical = $adventofcodeday['canonical']; ?> - Mikescher.com - <?php echo $title; ?> + Mikescher.com - <?php echo $htmltitle; ?> '; ?> diff --git a/www/statics/blog/__all.php b/www/statics/blog/__all.php index 9a13207..d696aff 100644 --- a/www/statics/blog/__all.php +++ b/www/statics/blog/__all.php @@ -24,6 +24,6 @@ return [ 'id' => 9, 'date' => '2016-10-22', 'visible' => true, 'title' => 'A complete sudoku solver in Befunge-93', 'fragment' => 'sudoku_befunge.md', 'type' => 'markdown', 'cat' => 'blog' ], [ 'id' => 21, 'date' => '2018-01-02', 'visible' => true, 'title' => 'A simple javascript befunge-93 runner', 'fragment' => 'js_befrunner.md', 'type' => 'markdown', 'cat' => 'blog' ], [ 'id' => 22, 'date' => '2018-02-06', 'visible' => true, 'title' => 'Homepage iteration 5', 'fragment' => 'v5.md', 'type' => 'markdown', 'cat' => 'log' ], - [ 'id' => 23, 'date' => '2019-11-02', 'visible' => true, 'title' => 'Advent of Code 2018', 'fragment' => '', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2018'] ], - [ 'id' => 24, 'date' => '2019-12-01', 'visible' => false, 'title' => 'Advent of Code 2019', 'fragment' => '', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2019'] ], + [ 'id' => 23, 'date' => '2019-11-02', 'visible' => true, 'title' => 'Advent of Code 2018', 'fragment' => 'aoc2018.txt', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2018'] ], + [ 'id' => 24, 'date' => '2019-12-01', 'visible' => false, 'title' => 'Advent of Code 2019', 'fragment' => 'aoc2019.txt', 'type' => 'aoc', 'cat' => 'blog', 'extras' => ['aoc:year' => '2019'] ], ]; \ No newline at end of file diff --git a/www/statics/blog/aoc2018.txt b/www/statics/blog/aoc2018.txt new file mode 100644 index 0000000..96d8608 --- /dev/null +++ b/www/statics/blog/aoc2018.txt @@ -0,0 +1,5 @@ +This is the first year I'm participating in the advent of code programming challenges. + +I intend to solve the puzzles with C# and Linqpad 5, just because that's the configuration I'm most confortable at writing small one-off scripts. + +If you haven't solved them by yourself be aware that clicking on the days below will spoiler the solutions and the second daily challenges... \ No newline at end of file diff --git a/www/statics/blog/aoc2019.txt b/www/statics/blog/aoc2019.txt new file mode 100644 index 0000000..5827ea4 --- /dev/null +++ b/www/statics/blog/aoc2019.txt @@ -0,0 +1 @@ +//TODO ENTER TEXT HERE \ No newline at end of file