Skip to content

Prepare website for 2024 #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
import java.io.File

ThisBuild / scalaVersion := "3.3.1"
ThisBuild / scalaVersion := "3.5.2"

lazy val adventOfCode = project
.in(file("."))
.enablePlugins(ScalaJSPlugin)
.settings(
(Compile / sourceGenerators) += taskPatchSolutions("2021", _ / "solutions" / "2021" / "src").taskValue,
(Compile / sourceGenerators) += taskPatchSolutions("2022", _ / "solutions" / "2022" / "src").taskValue,
(Compile / sourceGenerators) += taskPatchSolutions("2023", _ / "solutions" / "2023" / "src").taskValue,
Seq("2021", "2022", "2023", "2024")
.map(year => (Compile / sourceGenerators) += taskPatchSolutions(year).taskValue),
Compile / managedSourceDirectories := Nil,
run / fork := true,
run / baseDirectory := (ThisBuild / baseDirectory).value / "solutions"
)

def taskPatchSolutions(year: String, getSrcDir: File => File) = Def.task {
def taskPatchSolutions(year: String) = Def.task {
val s = streams.value
val cacheDir = s.cacheDirectory
val trgDir = (Compile / sourceManaged).value / s"solutions-$year-src"
val srcDir = getSrcDir((ThisBuild / baseDirectory).value)
val srcDir = (ThisBuild / baseDirectory).value / "solutions" / year / "src"

FileFunction.cached(cacheDir / s"fetch${year}Solutions",
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
s.log.info(s"Unpacking $year solutions sources to $trgDir...")
if (trgDir.exists)
IO.delete(trgDir)
IO.createDirectory(trgDir)
IO.copyDirectory(srcDir, trgDir)
val sourceFiles = (trgDir ** "*.scala").get.toSet
for (f <- sourceFiles)
IO.writeLines(f, patchSolutions(f.getName, year, IO.readLines(f)))
sourceFiles
} (Set(srcDir)).toSeq
FileFunction
.cached(
cacheDir / s"fetch${year}Solutions",
FilesInfo.lastModified,
FilesInfo.exists
) { dependencies =>
s.log.info(s"Unpacking $year solutions sources to $trgDir...")
if (trgDir.exists)
IO.delete(trgDir)
IO.createDirectory(trgDir)
IO.copyDirectory(srcDir, trgDir)
val sourceFiles = (trgDir ** "*.scala").get.toSet
for (f <- sourceFiles)
IO.writeLines(f, patchSolutions(f.getName, year, IO.readLines(f)))
sourceFiles
} (Set(srcDir))
.toSeq
}

/** adds `package adventofcode${year}` to the file after the last using directive */
Expand Down Expand Up @@ -61,8 +65,8 @@ lazy val solver = project
.enablePlugins(ScalaJSPlugin)
.settings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.3.0",
"com.raquo" %%% "laminar" % "0.14.5"
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
"com.raquo" %%% "laminar" % "17.1.0"
),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule))
)
Expand Down
4 changes: 4 additions & 0 deletions docs/2024/puzzles/day0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Day 0

[Advent of Code 2024](https://adventofcode.com/) has not started yet.
See you soon!
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0")
5 changes: 5 additions & 0 deletions solver/src/main/scala/adventofcode/Solver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import scala.util.{Try, Failure, Success}
import scala.scalajs.js.annotation.JSExportTopLevel

object Solver:
private val solutions2024: Map[String, String => Any] =
// import adventofcode2024.*
Map()

private val solutions2023: Map[String, String => Any] =
import adventofcode2023.*
Map(
Expand Down Expand Up @@ -109,6 +113,7 @@ object Solver:

private val solutions: Map[String, Map[String, String => Any]] =
Map(
"2024" -> solutions2024,
"2023" -> solutions2023,
"2022" -> solutions2022,
"2021" -> solutions2021,
Expand Down
6 changes: 6 additions & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const config = {
position: 'left',
label: 'Setup',
},
{
type: 'dropdown',
position: 'left',
label: 'Puzzles 2024',
items: buildDropdown('2024/puzzles')
},
{
type: 'dropdown',
position: 'left',
Expand Down
3 changes: 3 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const sidebars = {
adventOfCodeSidebar: [
'introduction',
'setup',
{
"2024 Puzzles": buildSidebar('2024/puzzles'),
},
{
"2023 Puzzles": buildSidebar('2023/puzzles'),
},
Expand Down
42 changes: 42 additions & 0 deletions website/src/pages/2024/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import clsx from 'clsx';
import Layout from '@theme/Layout';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import styles from '../index.module.css';
import HomepageFeatures from '../../components/HomepageFeatures';
import DocsLinks from '../../components/DocsLinks';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
return (
<header className={clsx('hero hero--primary', styles.heroBanner)}>
<div className="container">
<h1 className="hero__title" style={{ textShadow: "2px 2px 4px #000000"}}>
Scala Advent of Code 2024 by
<a href="https://scala.epfl.ch/">
<img className={styles.scalacenter} alt="Scala Center" src={useBaseUrl('/img/scala-center.png')} title="Scala Center"/>
</a>
</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div className={styles.buttons}>
<DocsLinks dir="2024/puzzles" linkStyle={`${styles.button} button button--secondary button--lg`} />
</div>
</div>
</header>
);
}

export default function Home() {
const {siteConfig} = useDocusaurusContext();
return (
<Layout
title={siteConfig.title}
description="Scala advent of code by the scala center">
<HomepageHeader />
<main>
<HomepageFeatures />
</main>
</Layout>
);
}
5 changes: 5 additions & 0 deletions website/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function HomepageHeader() {
to="/2023/">
2023
</Link>
<Link
className={`${styles.button} button button--secondary button--lg`}
to="/2024/">
2024
</Link>
</div>
</div>
</header>
Expand Down