-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
193 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zone.nox; | ||
|
||
public enum Target { | ||
|
||
DEV, LOCAL_PRODUCTION, GLOBAL_PRODUCTION; | ||
|
||
static Target from(Main.Config config) { | ||
return switch (config.target().orElse("dev")) { | ||
case "dev" -> DEV; | ||
case "local" -> LOCAL_PRODUCTION; | ||
case "global" -> GLOBAL_PRODUCTION; | ||
default -> throw new IllegalArgumentException(); | ||
}; | ||
} | ||
|
||
public boolean embedLocalVideo() { | ||
return switch (this) { | ||
case DEV, LOCAL_PRODUCTION -> true; | ||
case GLOBAL_PRODUCTION -> false; | ||
}; | ||
} | ||
|
||
public boolean embedYouTubeVideo() { | ||
return switch (this) { | ||
case DEV, GLOBAL_PRODUCTION -> true; | ||
case LOCAL_PRODUCTION -> false; | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
nox.zone/src/main/java/zone/nox/components/PostBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package zone.nox.components; | ||
|
||
import dev.nipafx.ginevra.css.Css; | ||
import dev.nipafx.ginevra.css.CssStyle; | ||
import dev.nipafx.ginevra.css.CssStyled; | ||
import dev.nipafx.ginevra.html.Classes; | ||
import dev.nipafx.ginevra.html.CustomElement; | ||
import dev.nipafx.ginevra.html.Element; | ||
import dev.nipafx.ginevra.html.Video.Preload; | ||
import dev.nipafx.ginevra.outline.Resources; | ||
import zone.nox.data.Post; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static dev.nipafx.ginevra.html.HtmlElement.div; | ||
import static dev.nipafx.ginevra.html.HtmlElement.video; | ||
import static dev.nipafx.ginevra.html.JmlElement.html; | ||
import static dev.nipafx.ginevra.html.JmlElement.nothing; | ||
import static zone.nox.components.Components.header; | ||
|
||
public record PostBlock(Post post, int level, boolean embedLocalVideo, boolean embedYouTubeVideo) implements CustomElement, CssStyled<PostBlock.Style> { | ||
|
||
public record Style(Classes localVideo, Classes youTubeVideoContainer, Classes youTubeVideo, Css css) implements CssStyle { } | ||
private static final Style STYLE = Css.parse(Style.class, """ | ||
.localVideo { | ||
margin: 1em 2em 0.5em; | ||
border: 1px dotted var(--yellow); | ||
} | ||
.localVideo > video { | ||
display: block; | ||
width: 100% !important; | ||
height: auto !important; | ||
} | ||
/* the second container (below) can't have margins | ||
because they screw up the 16:9 padding-top computation, | ||
so we have *another* container, just for the margins */ | ||
.youTubeVideoContainer { | ||
margin: 1em 2em 0.5em; | ||
border: 1px dotted var(--yellow); | ||
} | ||
.youTubeVideo { | ||
position: relative; | ||
overflow: hidden; | ||
/* 16:9 portrait aspect ratio */ | ||
padding-top: 177.78%; | ||
} | ||
.youTubeVideo > iframe { | ||
display: block; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
border: 0; | ||
} | ||
"""); | ||
|
||
public PostBlock(Post post) { | ||
this(post, 1, false, false); | ||
} | ||
|
||
@Override | ||
public List<Element> compose() { | ||
var children = new ArrayList<Element>(); | ||
children.add(header(post, level)); | ||
if (embedLocalVideo) | ||
children.add(embeddedLocalVideo()); | ||
if (embedYouTubeVideo) | ||
children.add(embeddedYouTubeVideo()); | ||
children.addAll(post.content()); | ||
return children; | ||
} | ||
|
||
private Element embeddedLocalVideo() { | ||
return post | ||
.localVideo() | ||
.<Element> map(local -> div | ||
.classes(STYLE.localVideo()) | ||
.children(video | ||
.src(Resources.include(local + ".mp4")) | ||
.poster(Resources.include(local + ".jpg")) | ||
.height(711) | ||
.width(400) | ||
.preload(Preload.NONE) | ||
.controls(true))) | ||
.orElse(nothing); | ||
} | ||
|
||
private Element embeddedYouTubeVideo() { | ||
return post | ||
.youTubeId() | ||
.<Element>map(id -> div | ||
.classes(STYLE.youTubeVideoContainer()) | ||
.children(div | ||
.classes(STYLE.youTubeVideo()) | ||
.children(html.literal(""" | ||
<iframe src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"> | ||
</iframe> | ||
""".formatted(id))))) | ||
.orElse(nothing); | ||
} | ||
|
||
public PostBlock level(int level) { | ||
return new PostBlock(post, level, embedLocalVideo, embedYouTubeVideo); | ||
} | ||
|
||
public PostBlock embedLocalVideo(boolean embedLocalVideo) { | ||
return new PostBlock(post, level, embedLocalVideo, embedYouTubeVideo); | ||
} | ||
|
||
public PostBlock embedYouTubeVideo(boolean embedYouTubeVideo) { | ||
return new PostBlock(post, level, embedLocalVideo, embedYouTubeVideo); | ||
} | ||
|
||
@Override | ||
public Style style() { | ||
return STYLE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.