Skip to content

Commit

Permalink
Build search index on website
Browse files Browse the repository at this point in the history
  • Loading branch information
satabin committed Jan 14, 2023
1 parent cabb8d9 commit e1e6b16
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 31 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/publish-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ jobs:
run: "sbt 'set ThisBuild / tlFatalWarningsInCi := false' documentation/mdoc"
- name: "Build site"
run: "sbt 'set ThisBuild / tlFatalWarningsInCi := false' makeSite"
- name: "Install stork"
uses: actions-rs/cargo@v1
with:
command: install
args: stork-search --locked
- name: "Build search index"
run: 'stork build --input target/site/index.toml --output target/site/index.st'
- uses: actions/upload-artifact@v3
with:
name: site
Expand All @@ -33,3 +40,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/site
exclude_assets: '.github,**/index.toml'
10 changes: 3 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ val root = tlCrossRootProject
finiteState
)
.settings(commonSettings)
.enablePlugins(NoPublishPlugin, ScalaUnidocPlugin, SiteScaladocPlugin, NanocPlugin, GhpagesPlugin)
.enablePlugins(NoPublishPlugin, ScalaUnidocPlugin, SiteScaladocPlugin, NanocPlugin)
.settings(
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(
cbor.jvm,
Expand All @@ -133,15 +133,11 @@ val root = tlCrossRootProject
jsonInterpolators.jvm,
text.jvm,
xml.jvm,
scalaXml.jvm,
finiteState.jvm,
benchmarks.jvm
scalaXml.jvm
),
ScalaUnidoc / siteSubdirName := "api",
addMappingsToSiteDir(ScalaUnidoc / packageDoc / mappings, ScalaUnidoc / siteSubdirName),
Nanoc / sourceDirectory := file("site"),
git.remoteRepo := scmInfo.value.get.connection.replace("scm:git:", ""),
ghpagesNoJekyll := true
Nanoc / sourceDirectory := file("site")
)

lazy val text = crossProject(JVMPlatform, JSPlatform, NativePlatform)
Expand Down
2 changes: 0 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
Expand Down
5 changes: 5 additions & 0 deletions site/Rules
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ compile '/**/index.md' do
write item.identifier.without_ext + '.html'
end

compile '/**/*.toml' do
filter :erb
write item.identifier.to_s
end

compile '/api/**/*' do
write item.identifier.to_s
end
Expand Down
25 changes: 12 additions & 13 deletions site/content/css/materialize.min.css

Large diffs are not rendered by default.

191 changes: 191 additions & 0 deletions site/content/css/stork.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
.stork-wrapper-flat {
position: relative;
font-family: inherit;
box-sizing: border-box;
font-size: 1em;

--stork-blue-2: #a5d8ff;
--stork-blue-3: #74c0fc;
--stork-blue-4: #4dabf7;
--stork-blue-5: #339af0;
--stork-blue-7: #1c7ed6;
--stork-gray-8: #343a40;
--stork-gray-9: #212529;
--stork-yellow-2: #ffec99;

--stork-border-color: hsl(0, 0%, 80%);
--stork-background-color: hsla(0, 0%, 97%);
--stork-text-color: var(--stork-gray-9);

--stork-input-height: 2.4em;
}

.stork-wrapper-flat *,
.stork-wrapper-flat *:before,
.stork-wrapper-flat *:after {
box-sizing: border-box;
}

.stork-wrapper-flat .stork-input {
width: 100%;
height: var(--stork-input-height);
font-size: 1em;
padding: 0.4em 0.8em;
position: relative;
border: 2px solid var(--stork-border-color);
border-radius: calc(var(--stork-input-height) / 2);
background-color: var(--stork-background-color);
color: var(--stork-text-color);
font-family: inherit;
}

.stork-wrapper-flat .stork-input:focus {
outline: none;
}

.stork-wrapper-flat .stork-progress {
position: absolute;
display: block;
content: "";
bottom: 1px;
background-color: var(--stork-blue-5);
box-shadow: 0 0 8px var(--stork-blue-4);
height: 1px;
transition: width 0.25s ease, opacity 0.4s ease 0.4s;
margin-left: calc(var(--stork-input-height) / 2);
max-width: calc(100% - var(--stork-input-height));
}

.stork-wrapper-flat .stork-output {
position: absolute;
width: 100%;
margin-top: 0.5em;
border-radius: 6px;
display: flex;
flex-direction: column;
z-index: 100;
color: var(--stork-text-color);
font-weight: 400;
font-family: inherit;
}

.stork-wrapper-flat .stork-attribution a:link,
.stork-wrapper-flat .stork-attribution a:visited {
color: var(--stork-blue-7);
}

.stork-wrapper-flat .stork-output-visible {
border: 2px solid var(--stork-border-color);
background: var(--stork-background-color);
}

.stork-wrapper-flat .stork-message {
width: 100%;
padding: 0.5em 1em;
color: var(--stork-text-color);
}

.stork-wrapper-flat .stork-attribution {
width: 100%;
padding: 0.5em 1em;
font-size: 0.8em;
color: var(--stork-text-color);
}

.stork-wrapper-flat .stork-results {
margin: 0;
padding: 0;
width: 100%;
list-style-type: none;
max-height: 25em;
overflow-y: scroll;
border-top: 1px solid var(--stork-border-color);
border-bottom: 1px solid var(--stork-border-color);
}

.stork-wrapper-flat .stork-result:not(:last-child) {
border-bottom: 1px solid var(--stork-border-color);
}

.stork-wrapper-flat .stork-result.selected {
background: var(--stork-blue-2);
}

.stork-wrapper-flat .stork-result a:link {
padding: 1em;
display: block;
color: currentcolor;
text-decoration: none;
}

.stork-wrapper-flat .stork-result p {
margin: 0;
}

.stork-wrapper-flat .stork-title {
font-weight: bold;
font-size: 0.95em;
margin: 0;
color: var(--stork-text-color);

/* Flexbox container for the title and the score, when debugging */
display: flex;
justify-content: space-between;
}

.stork-wrapper-flat .stork-excerpt-container {
margin-top: 0.75em;
}

.stork-wrapper-flat .stork-excerpt {
font-size: 0.8em;
line-height: 1;
margin: 0;
color: var(--stork-gray-8);

/* Flexbox container for the title and the score, when debugging */
display: flex;
justify-content: space-between;
}

.stork-wrapper-flat .stork-excerpt:not(:last-of-type) {
margin-bottom: 0.6em;
}

.stork-wrapper-flat .stork-highlight {
background-color: var(--stork-yellow-2);
padding: 0 0.1em;
}

.stork-wrapper-flat .stork-error {
outline: 2px solid #c92a2a;
}

.stork-wrapper-flat .stork-close-button {
position: absolute;
right: 0;
margin: 0.5em 0.5em;
height: 1.4em;
width: 1.4em;
padding: 0px;
background: hsl(0, 0%, 85%);
border: 1px solid hsla(0, 0%, 70%);
font-size: 1em;
color: hsl(0, 0%, 50%);
border-radius: 50%;
line-height: 1;
}

.stork-wrapper-flat .stork-close-button svg {
width: 11px;
height: 11px;
}

.stork-wrapper-flat .stork-close-button:hover {
background: hsla(0, 0%, 78%);
cursor: pointer;
}

.stork-wrapper-flat .stork-close-button:active {
background: hsla(0, 0%, 65%);
}
11 changes: 11 additions & 0 deletions site/content/index.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[input]
<% @items.find_all('/documentation/**/*.md').each do |item| %>
[[input.files]]
path = "<%= item.reps[:default].raw_path %>"
url = "<%= item.path %>"
title = "<%= strip_html(item[:title]) %>"
<% end %>

[output]
excerpts_per_result = 3
displayed_results_count = 5
12 changes: 6 additions & 6 deletions site/content/js/materialize.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions site/content/js/stork.js

Large diffs are not rendered by default.

Binary file added site/content/js/stork.wasm
Binary file not shown.
23 changes: 21 additions & 2 deletions site/layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<link type="text/css" rel="stylesheet" href="/css/materialize.min.css" media="screen,projection"/>
<style>body{font-family: overpass, sans-serif; }</style>

<script type="text/javascript" src="/js/materialize.min.js"></script>

<!-- search index -->
<link rel="stylesheet" href="/css/stork.css" />
<script src="/js/stork.js"></script>

<meta name="generator" content="Nanoc <%= Nanoc::VERSION %>">
</head>
<body>
Expand All @@ -22,6 +28,14 @@
<li><a href="/documentation/">Documentation</a></li>
<li><a href="/api/">Scaladoc</a></li>
<li><a href="https://github.com/gnieh/fs2-data">Github</a></li>
<li><i class="material-icons">search</i></li>
<li>
<form>
<div class="input-field">
<input data-stork="search" id="search" type="search" required placeholder="Search the website" autocomplete="off" />
</div>
</form>
</li>
</ul>
</div>
<%# top level doc trick %>
Expand All @@ -47,6 +61,9 @@
</div>
<% end %>
</nav>
<div class="stork-wrapper-flat">
<div data-stork="search-output" class="stork-output"></div>
</div>

</header>

Expand Down Expand Up @@ -83,7 +100,6 @@
</div>
</footer>

<script type="text/javascript" src="/js/materialize.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
Expand All @@ -93,6 +109,9 @@
var elems = document.querySelectorAll('.tooltipped');
var instances = M.Tooltip.init(elems, {});
});

stork.initialize("/js/stork.wasm")
stork.register("search", "/index.st", { showCloseButton: false })
</script>
</body>

</html>
2 changes: 2 additions & 0 deletions site/lib/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use_helper Nanoc::Helpers::Text

def modules_by_type
@items.find_all("/documentation/*/index.md").group_by do |item|
item[:type]
Expand Down
2 changes: 1 addition & 1 deletion site/nanoc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A list of file extensions that Nanoc will consider to be textual rather than
# binary. If an item with an extension not in this list is found, the file
# will be considered as binary.
text_extensions: [ 'adoc', 'asciidoc', 'atom', 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss', 'slim', 'tex', 'txt', 'xhtml', 'xml' ]
text_extensions: [ 'adoc', 'asciidoc', 'atom', 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss', 'slim', 'tex', 'txt', 'xhtml', 'xml', 'toml']

base_url: https://fs2-data.gnieh.org

Expand Down

0 comments on commit e1e6b16

Please sign in to comment.