Skip to content

Commit 247c7a5

Browse files
tuanpham96rlygithub-actions[bot]github-actions[bot]github-actions[bot]
authored
Offload API to static files + Fix search bug (#17)
Co-authored-by: Ryan Ly <[email protected]> Co-authored-by: github-actions[bot] <runner@fv-az618-841.ogsaqtoyx52uhcfy3b1k3wjvzc.jx.internal.cloudapp.net> Co-authored-by: github-actions[bot] <runner@fv-az1230-275.pnbcmxnyn2burpnk1ig1bplgja.jx.internal.cloudapp.net> Co-authored-by: github-actions[bot] <runner@fv-az167-507.10vc1fp43w4ejfym3u1nh0imhc.jx.internal.cloudapp.net> Co-authored-by: github-actions[bot] <runner@fv-az247-115.pyoqamc1z0nuzhu5fvcxfugxug.jx.internal.cloudapp.net> Co-authored-by: github-actions[bot] <runner@fv-az1442-795.gtdgxysclnuenlnkab13ghtgjb.cx.internal.cloudapp.net>
1 parent 5634b02 commit 247c7a5

File tree

13 files changed

+284
-57
lines changed

13 files changed

+284
-57
lines changed

.github/workflows/data.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Download records & Push to repository
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
schedule:
7+
# Run at 8:00 on working days
8+
- cron: 0 8 * * 0-5
9+
workflow_dispatch:
10+
11+
12+
jobs:
13+
download:
14+
runs-on: ubuntu-latest
15+
if: ${{ !startsWith(github.event.head_commit.message, '[bot]') }}
16+
environment:
17+
name: download-data
18+
env:
19+
CI_COMMIT_USER: 'github-actions[bot]'
20+
CI_COMMIT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
21+
CI_COMMIT_MESSAGE: '[bot] update records'
22+
CI_PUSH_REMOTE: [email protected]:$GITHUB_REPOSITORY.git
23+
CI_PUSH_BRANCH: 'main'
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
token: ${{ secrets.NWB_EXTENSIONS_BOT_GITHUB_TOKEN }}
28+
persist-credentials: true
29+
- uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.12'
32+
cache: 'pip'
33+
- run: |
34+
pip install -r utils/requirements.txt
35+
- name: Download records data
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # in future, consider replace with PAT
38+
run: |
39+
python utils/collect-records.py
40+
- name: Commit & Push to repository
41+
run: |
42+
git config user.name "${{ env.CI_COMMIT_USER }}"
43+
git config user.mail "${{ env.CI_COMMIT_EMAIL }}"
44+
45+
if [[ `git diff data` ]] ; then
46+
git add data
47+
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
48+
git push "${{ env.CI_PUSH_REMOTE }}" "HEAD:${{ env.CI_PUSH_BRANCH }}"
49+
else
50+
echo "No changes were found in data"
51+
exit 0
52+
fi

.github/workflows/jekyll.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
7+
name: Deploy Jekyll site to Pages
8+
9+
on:
10+
# Runs on pushes targeting the default branch
11+
push:
12+
branches: ["main"]
13+
14+
# Allows you to run this workflow manually from the Actions tab
15+
workflow_dispatch:
16+
17+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
18+
permissions:
19+
contents: read
20+
pages: write
21+
id-token: write
22+
23+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
24+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
25+
concurrency:
26+
group: "pages"
27+
cancel-in-progress: false
28+
29+
jobs:
30+
# Build job
31+
build:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
- name: Setup Ruby
37+
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
38+
with:
39+
ruby-version: '3.1' # Not needed with a .ruby-version file
40+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
41+
cache-version: 0 # Increment this number if you need to re-download cached gems
42+
- name: Setup Pages
43+
id: pages
44+
uses: actions/configure-pages@v3
45+
- name: Build with Jekyll
46+
# Outputs to the './_site' directory by default
47+
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
48+
env:
49+
JEKYLL_ENV: production
50+
- name: Upload artifact
51+
# Automatically uploads an artifact from the './_site' directory by default
52+
uses: actions/upload-pages-artifact@v2
53+
54+
# Deployment job
55+
deploy:
56+
environment:
57+
name: github-pages
58+
url: ${{ steps.deployment.outputs.page_url }}
59+
runs-on: ubuntu-latest
60+
needs: build
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ _site
44
.vagrant
55
.jekyll-cache
66
Gemfile.lock
7+
.jekyll-metadata
8+
.venv
79

810
# general
911
.DS_Store

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
22

33
gem 'jekyll'
44
gem 'jekyll-scholar'
5+
gem 'kramdown-parser-gfm'

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
get-records: ## Get records data
2+
python utils/collect-records.py
3+
4+
serve: ## Serve and allow tracking changes to _config.yml with
5+
npx watchy -w _config.yml -- bundle exec jekyll serve --incremental --watch --livereload
6+
7+
cache-clean: ## Clean cache
8+
bundle exec jekyll clean
9+
10+
clean: # Clean
11+
rm -rf _site
12+
make cache-clean

_config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ title: Neuro Data Extensions (NDX) Catalog
1010
1111
description: > # this means to ignore newlines until "baseurl:"
1212
Web page for technical content for HDMF
13-
exclude: ["README.md", "Gemfile" ]
13+
1414
url: ""
1515

1616
include:
1717
- _pages
18+
exclude:
19+
- "README.md"
20+
- "Gemfile"
21+
- utils
22+
- .github
1823

1924
sass:
2025
sass_dir: _sass

_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<span class="icon-bar"></span>
88
<span class="icon-bar"></span>
99
</button>
10-
<a class="navbar-brand" href="{{ site.url }}{{ site.baseurl }}/"><img alt="NDX Catalog" src="/images/ndx-logo-text-long.png" height="42px"></a>
10+
<a class="navbar-brand" href="{{ site.url }}{{ site.baseurl }}/"><img alt="NDX Catalog" src="{{ site.baseurl }}/images/ndx-logo-text-long.png" height="42px"></a>
1111
</div>
1212
<div class="collapse navbar-collapse" id="navbar-collapse-1">
1313
<ul class="nav navbar-nav navbar-right">

_pages/home.md

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,65 +19,34 @@ The [Neurodata Extensions Catalog (NDX Catalog)](https://github.com/nwb-extensio
1919
<p><span id="search-process" style="display: none">Showing <span id="search-results-count"></span> results for "<strong id="search-query"></strong>"</span><span id="show-all" style="display: none">Showing <span id="show-all-count"></span> extensions</span></p>
2020
<ul id="search-results"></ul>
2121

22-
<script src="{{ site.url }}/js/lunr.min.js"></script>
23-
<script src="{{ site.url }}/js/jquery-3.5.0.min.js" ></script>
24-
<script src="{{ site.url }}/js/js-yaml.min.js" ></script>
22+
<script src="{{ site.url }}{{ site.baseurl }}/js/lunr.min.js"></script>
23+
<script src="{{ site.url }}{{ site.baseurl }}/js/jquery-3.5.0.min.js" ></script>
24+
<script src="{{ site.url }}{{ site.baseurl }}/js/js-yaml.min.js" ></script>
2525
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
26+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js"></script>
2627

2728
<script>
2829
(function() {
29-
window.data = {}
3030

31-
function loadSearch() {
32-
var fileref = document.createElement('script')
33-
fileref.setAttribute("type", "text/javascript")
34-
fileref.setAttribute("src", "{{ site.baseurl }}/js/search.js")
35-
document.getElementsByTagName("head")[0].appendChild(fileref)
36-
}
37-
38-
$.getJSON("https://api.github.com/orgs/{{ site.github_username }}/repos").done(function(data) {
39-
countTotal = 0
40-
$.each(data, function(key, recordJson) {
41-
if (recordJson.name.startsWith("{{ site.prefix }}") && recordJson.name.endsWith("{{ site.suffix }}") ) {
42-
countTotal += 1
43-
}
31+
function loadSearch() {
32+
var fileref = document.createElement('script')
33+
fileref.setAttribute("type", "text/javascript")
34+
fileref.setAttribute("src", "{{ site.baseurl }}/js/search.js")
35+
document.getElementsByTagName("head")[0].appendChild(fileref)
36+
}
37+
38+
$.getJSON('{{ site.baseurl }}/data/records.json').done(function(data) {
39+
Object.keys(data).forEach(key=>{
40+
// add DOMPurify to sanitize parsed HTML, because marked doesn't sanitize
41+
data[key].readme = DOMPurify.sanitize(
42+
marked.parse(data[key].readme)
43+
);
44+
// data[key].pypi_version_badge = "https://img.shields.io/pypi/v/" + data[key].name;
45+
});
46+
window.data = data;
47+
loadSearch();
4448
});
45-
countLoaded = 0
46-
$.each(data, function(key, recordJson) {
47-
if (recordJson.name.startsWith("{{ site.prefix }}") && recordJson.name.endsWith("{{ site.suffix }}") ) {
48-
var resultJson = {}
49-
resultJson.ref = recordJson.name
50-
resultJson.record_url = recordJson.html_url
51-
resultJson.last_updated = recordJson.pushed_at
52-
window.data[recordJson.name] = resultJson
53-
54-
var metaUrl = "https://api.github.com/repos/{{ site.github_username }}/" + recordJson.name + "/contents/ndx-meta.yaml"
55-
$.getJSON(metaUrl).done(function(res, status) {
56-
if (status == "success") {
57-
metaJson = jsyaml.load(atob(res.content))
58-
for (k in metaJson) {
59-
window.data[recordJson.name][k] = metaJson[k]
60-
}
61-
}
62-
var readmeUrl = "https://api.github.com/repos/{{ site.github_username }}/" + recordJson.name + "/contents/README.md"
63-
$.getJSON(readmeUrl).done(function(res, status) {
64-
if (status == "success") {
65-
readmeText = atob(res.content)
66-
var readmeHtml = marked.parse(readmeText)
67-
window.data[recordJson.name].readme = readmeHtml
68-
69-
countLoaded += 1
70-
if (countLoaded == countTotal) {
71-
loadSearch()
72-
}
73-
}
74-
});
75-
});
76-
}
77-
});
78-
});
7949
})();
80-
8150
</script>
8251

8352
</div>

css/main.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,19 @@ table {
215215
position: relative;
216216
padding-right: 20px;
217217
}
218+
219+
.readme-preview h1 {
220+
font-size: 24px;
221+
}
222+
223+
.readme-preview h2 {
224+
font-size: 20px;
225+
}
226+
227+
.readme-preview h3 {
228+
font-size: 16px;
229+
}
230+
231+
.readme-preview h4 h5 h6 {
232+
font-size: 12px;
233+
}

data/records.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)