Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
howto-cards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roland Krause
howto-cards
Commits
46882134
Verified
Commit
46882134
authored
4 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
move scripts to separate html files
parent
e9f16085
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
_includes/scripts.html
+2
-0
2 additions, 0 deletions
_includes/scripts.html
_includes/search.html
+87
-0
87 additions, 0 deletions
_includes/search.html
index.md
+1
-3
1 addition, 3 deletions
index.md
search.md
+1
-87
1 addition, 87 deletions
search.md
with
91 additions
and
90 deletions
_includes/scripts.html
+
2
−
0
View file @
46882134
<script
type=
"text/javascript"
src=
"https://analytics.lcsb.uni.lu/lap/static/js/jquery.min.js"
></script>
<script
type=
"text/javascript"
src=
"{{ "
assets
/
js
/
router.js
"
|
relative_url
}}"
></script>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
_includes/search.html
0 → 100644
+
87
−
0
View file @
46882134
<link
rel=
"prefetch"
href=
"index.js"
/>
<form>
<input
class=
"search"
placeholder=
"What are you looking for?"
name=
"search_query"
id=
"search_query"
/><br
/>
<button
class=
"search"
type=
"submit"
>
Find it
</button>
</form>
<h1
id=
"search_header"
>
Results of your query:
</h1>
<table
id=
"search_results_table"
>
<tbody
id=
"search_results_tbody"
>
<tr
id=
"search_results_placeholder"
style=
"display: none"
>
<td
id=
"search_results_placeholder_td"
><h3>
Please wait, search is in progress...
</h3></td>
</tr>
</tbody>
</table>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.8/lunr.min.js"
integrity=
"sha256-34Si1Y6llMBKM3G0jQILVeoQKEwuxjbk4zGWXXMT4ps="
crossorigin=
"anonymous"
></script>
<script>
var
el_table_body
=
document
.
getElementById
(
'
search_results_tbody
'
);
var
el_input_query
=
document
.
getElementById
(
'
search_query
'
);
var
el_tr_placeholder
=
document
.
getElementById
(
'
search_results_placeholder
'
);
var
el_header
=
document
.
getElementById
(
'
search_header
'
);
var
url_params
=
new
URLSearchParams
(
window
.
location
.
search
);
var
search_term
=
url_params
.
get
(
'
search_query
'
)
||
""
;
if
(
!!
search_term
.
length
)
{
el_input_query
.
value
=
search_term
;
el_header
.
style
.
display
=
"
block
"
;
el_tr_placeholder
.
style
.
display
=
"
block
"
;
}
var
construct_cell
=
function
(
title
,
content
,
link
)
{
if
(
link
==
'
#
'
)
{
return
'
<td><h3 class="result">
'
+
title
+
'
</h3><p>
'
+
content
+
'
</p></td>
'
;
}
else
{
return
'
<td><h3><a href="
'
+
link
+
'
">
'
+
title
+
'
</a></h3><p>
'
+
content
+
'
</p></td>
'
;
}
}
var
capitalize
=
function
(
text
)
{
return
text
.
charAt
(
0
).
toUpperCase
()
+
text
.
slice
(
1
);
}
var
prettify
=
function
(
text
)
{
return
text
.
split
(
'
:
'
).
map
(
capitalize
).
join
(
'
»
'
);
}
{
%
assign
the_cards
=
site
.
pages
|
where_exp
:
"
card
"
,
"
card.searchable >= 1.0
"
%
}
window
.
content
=
{
{
%
for
card
in
the_cards
%
}
"
{{ card.url | slugify }}
"
:
{
"
title
"
:
"
{{ card.shortcut | xml_escape }}
"
,
"
content
"
:
{{
card
.
content
|
strip_html
|
strip_newlines
|
jsonify
}},
"
url
"
:
"
{{ card.url | xml_escape | relative_url }}
"
}
{
%
unless
forloop
.
last
%
},{
%
endunless
%
}
{
%
endfor
%
}
};
fetch
(
'
{{ "index.js" | relative_url }}
'
).
then
(
response
=>
response
.
text
()).
then
((
data
)
=>
{
var
the_index
=
JSON
.
parse
(
data
);
window
.
search_index
=
lunr
.
Index
.
load
(
the_index
);
if
(
search_term
!=
""
)
{
var
results
=
window
.
search_index
.
search
(
search_term
);
for
(
var
i
=
0
;
i
<
results
.
length
;
i
++
)
{
var
node
=
document
.
createElement
(
"
tr
"
);
node
.
innerHTML
=
construct_cell
(
prettify
(
window
.
content
[
results
[
i
].
ref
].
title
),
window
.
content
[
results
[
i
].
ref
].
content
.
substring
(
0
,
125
)
+
'
...
'
,
window
.
content
[
results
[
i
].
ref
].
url
);
el_table_body
.
appendChild
(
node
);
}
if
(
results
.
length
==
0
)
{
var
node
=
document
.
createElement
(
"
tr
"
);
node
.
innerHTML
=
construct_cell
(
"
No results
"
,
'
Sorry, we were unable to find anything that matches your query
'
,
"
#
"
);
el_table_body
.
appendChild
(
node
);
}
}
el_tr_placeholder
.
style
.
display
=
"
none
"
;
})
</script>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
index.md
+
1
−
3
View file @
46882134
...
...
@@ -4,9 +4,7 @@ title: Home
order
:
1
---
<script
type=
"text/javascript"
src=
"https://analytics.lcsb.uni.lu/lap/static/js/jquery.min.js"
></script>
<script
type=
"text/javascript"
src=
"{{ "
assets
/
js
/
router.js
"
|
relative_url
}}"
></script>
{% include scripts.html %}
# LCSB How-to Cards
...
...
This diff is collapsed.
Click to expand it.
search.md
+
1
−
87
View file @
46882134
...
...
@@ -5,90 +5,4 @@ permalink: /search
order
:
4
---
<link
rel=
"prefetch"
href=
"index.js"
/>
<form>
<input
class=
"search"
placeholder=
"What are you looking for?"
name=
"search_query"
id=
"search_query"
/><br
/>
<button
class=
"search"
type=
"submit"
>
Find it
</button>
</form>
<h1
id=
"search_header"
>
Results of your query:
</h1>
<table
id=
"search_results_table"
>
<tbody
id=
"search_results_tbody"
>
<tr
id=
"search_results_placeholder"
style=
"display: none"
>
<td
id=
"search_results_placeholder_td"
><h3>
Please wait, search is in progress...
</h3></td>
</tr>
</tbody>
</table>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.8/lunr.min.js"
integrity=
"sha256-34Si1Y6llMBKM3G0jQILVeoQKEwuxjbk4zGWXXMT4ps="
crossorigin=
"anonymous"
></script>
<script>
var el_table_body = document.getElementById('search_results_tbody');
var el_input_query = document.getElementById('search_query');
var el_tr_placeholder = document.getElementById('search_results_placeholder');
var el_header = document.getElementById('search_header');
var url_params = new URLSearchParams(window.location.search);
var search_term = url_params.get('search_query') || "";
if (!!search_term.length) {
el_input_query.value = search_term;
el_header.style.display = "block";
el_tr_placeholder.style.display = "block";
}
var construct_cell = function(title, content, link) {
if (link == '#') {
return '<td><h3 class="result">' + title + '</h3><p>' + content + '</p></td>';
} else {
return '<td><h3><a href="' + link + '">' + title + '</a></h3><p>' + content + '</p></td>';
}
}
var capitalize = function(text) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
var prettify = function(text) {
return text.split(':').map(capitalize).join(' » ');
}
{% assign the_cards = site.pages | where_exp:"card","card.searchable >= 1.0" %}
window.content = { {% for card in the_cards %}
"{{ card.url | slugify }}": {
"title": "{{ card.shortcut | xml_escape }}",
"content": {{ card.content | strip_html | strip_newlines | jsonify }},
"url": "{{ card.url | xml_escape | relative_url }}"
} {% unless forloop.last %},{% endunless %} {% endfor %}
};
fetch('{{ "index.js" | relative_url }}').then(response => response.text()).then((data) => {
var the_index = JSON.parse(data);
window.search_index = lunr.Index.load(the_index);
if (search_term != "") {
var results = window.search_index.search(search_term);
for (var i = 0; i < results.length; i++) {
var node = document.createElement("tr");
node.innerHTML = construct_cell(prettify(window.content[results[i].ref].title),
window.content[results[i].ref].content.substring(0, 125) + '...',
window.content[results[i].ref].url);
el_table_body.appendChild(node);
}
if (results.length == 0) {
var node = document.createElement("tr");
node.innerHTML = construct_cell("No results",
'Sorry, we were unable to find anything that matches your query',
"#");
el_table_body.appendChild(node);
}
}
el_tr_placeholder.style.display = "none";
})
</script>
{% include search.html %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment