Skip to content

Commit 85e994a

Browse files
committed
Add js for table controlling query params
1 parent b64f4ec commit 85e994a

4 files changed

Lines changed: 111 additions & 69 deletions

File tree

‎.github/workflows/links.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
Links:
88
runs-on: ubuntu-latest
99
env:
10-
USER_AGENT: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36
10+
USER_AGENT: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
1111
steps:
1212
- name: Download prod build
1313
uses: dawidd6/action-download-artifact@master

‎_layouts/content-category.html‎

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h1 class="post-title">{{ page.title | escape }}</h1>
1212

1313
<div class="post-content">
1414
{{ content }}
15-
{% assign contents = site.content | where: "category", page.slug | sort: "slug" | reverse | sort: "expected_value", "first" | reverse %}
15+
{%- assign contents = site.content | where: "category", page.slug | sort: "slug" | reverse | sort: "expected_value", "first" | reverse -%}
1616
<table id="mainContentList">
1717
<thead>
1818
<th>Name</th>
@@ -25,91 +25,92 @@ <h1 class="post-title">{{ page.title | escape }}</h1>
2525
<th><i class="fas fa-cloud-arrow-down"></i><span style="display: none">Downloads</span></th>
2626
</thead>
2727
<tbody>
28-
{% for p in contents %}
28+
{%- for p in contents -%}
2929
<tr id="{{ p.slug }}">
30-
<td><a href="{{ p.url }}" target="_blank">{% include_cached content_icon.html category=page.slug subcat=p.subcat %} {{ p.title | markdownify | remove: '<p>' | remove: '</p>' }}</a></td>
31-
<td>{% include content_filelinks.html content=p newtab=true %}</td>
30+
<td><a href="{{ p.url }}" target="_blank">{%- include_cached content_icon.html category=page.slug subcat=p.subcat -%} {{ p.title | markdownify | remove: '<p>' | remove: '</p>' }}</a></td>
31+
<td>{%- include content_filelinks.html content=p newtab=true -%}</td>
3232
<td>{{ p.year }}</td>
3333
<td>{%- if p.authors.size > 0 -%}
34-
{% include_cached content_authors_string.html content=p %}
34+
{%- include_cached content_authors_string.html content=p -%}
3535
{%- elsif p.editor -%}
36-
{% assign editors = p.editor | split: " and " %}
37-
{% include_cached content_authors_string.html authors=editors %}
36+
{%- assign editors = p.editor | split: " and " -%}
37+
{%- include_cached content_authors_string.html authors=editors -%}
3838
{%- elsif p.reader -%}
39-
{% assign readers = p.reader | split: " and " %}
40-
{% include_cached content_authors_string.html authors=readers %}
39+
{%- assign readers = p.reader | split: " and " -%}
40+
{%- include_cached content_authors_string.html authors=readers -%}
4141
{%- elsif p.translator -%}
42-
{% assign translators = p.translator | split: " and " %}
43-
{% include_cached content_authors_string.html authors=translators %}
42+
{%- assign translators = p.translator | split: " and " -%}
43+
{%- include_cached content_authors_string.html authors=translators -%}
4444
{%- endif -%}
4545
</td>
4646
{%- assign primarytag = false -%}
47-
{% assign ordinality = 9999 %}
48-
{% if p.course %}
49-
{% for candidatecourse in site.courses %}
50-
{% if p.course == candidatecourse.slug %}
51-
{% capture primarytag %}<a href="{{ candidatecourse.url }}">
47+
{%- assign ordinality = 9999 -%}
48+
{%- if p.course -%}
49+
{%- for candidatecourse in site.courses -%}
50+
{%- if p.course == candidatecourse.slug -%}
51+
{%- capture primarytag -%}<a href="{{ candidatecourse.url }}">
5252
<i class="{{ candidatecourse.icon }}"></i>
5353
{{ candidatecourse.title | escape }}
54-
</a>{% endcapture %}
55-
{% assign ordinality = forloop.index %}
56-
{% break %}
57-
{% endif %}
58-
{% endfor %}
59-
{% unless primarytag %}
60-
{% for candidatetag in site.tags %}
61-
{% if candidatetag.slug == p.course %}
62-
{% capture primarytag %}<a href="{{ candidatetag.url }}">
54+
</a>{%- endcapture -%}
55+
{%- assign ordinality = forloop.index -%}
56+
{%- break -%}
57+
{%- endif -%}
58+
{%- endfor -%}
59+
{%- unless primarytag -%}
60+
{%- for candidatetag in site.tags -%}
61+
{%- if candidatetag.slug == p.course -%}
62+
{%- capture primarytag -%}<a href="{{ candidatetag.url }}">
6363
<i class="fas fa-tag"></i>
6464
{{ candidatetag.title | escape }}
65-
</a>{% endcapture %}
66-
{% assign ordinality = forloop.index | plus: site.courses.size %}
67-
{% break %}
68-
{% endif %}
69-
{% endfor %}
70-
{% endunless %}
71-
{% endif %}
72-
{% unless primarytag %}
73-
{% for candidatetag in site.tags %}
74-
{% if p.tags contains candidatetag.slug %}
75-
{% capture primarytag %}<a href="{{ candidatetag.url }}">
65+
</a>{%- endcapture -%}
66+
{%- assign ordinality = forloop.index | plus: site.courses.size -%}
67+
{%- break -%}
68+
{%- endif -%}
69+
{%- endfor -%}
70+
{%- endunless -%}
71+
{%- endif -%}
72+
{%- unless primarytag -%}
73+
{%- for candidatetag in site.tags -%}
74+
{%- if p.tags contains candidatetag.slug -%}
75+
{%- capture primarytag -%}<a href="{{ candidatetag.url }}">
7676
<i class="fas fa-tag"></i>
7777
{{ candidatetag.title | escape }}
78-
</a>{% endcapture %}
79-
{% assign ordinality = forloop.index | plus: site.courses.size %}
80-
{% break %}
81-
{% endif %}
82-
{% endfor %}
78+
</a>{%- endcapture -%}
79+
{%- assign ordinality = forloop.index | plus: site.courses.size -%}
80+
{%- break -%}
81+
{%- endif -%}
82+
{%- endfor -%}
8383
{%- endunless -%}
8484
<td data-order="{{ ordinality }}">
85-
{% if primarytag %}
85+
{%- if primarytag -%}
8686
{{ primarytag }}
87-
{% endif %}
87+
{%- endif -%}
8888
</td>
8989
<td>
9090
{{ p.date | date: "%Y-%m-%d %H:%M" }}
9191
</td>
9292
<td data-order="{{ p.total_mins }}">
93-
{% include content_size.html content=p %}
93+
{%- include content_size.html content=p -%}
9494
</td>
9595
<td>
96-
{% assign plus = 1 %}
97-
{% unless p.external_url or p.drive_links.size > 0 %}{% assign plus = 0 %}{% endunless %}
96+
{%- assign plus = 1 -%}
97+
{%- unless p.external_url or p.drive_links.size > 0 -%}{%- assign plus = 0 -%}{%- endunless -%}
9898
{{ site.data.content_downloads[p.content_path] | default: 0 | plus: plus }}
9999
</td>
100100
</tr>
101-
{% endfor %}
101+
{%- endfor -%}
102102
</tbody>
103103
</table>
104104
</div>
105105

106106
</article>
107107

108-
<link rel="stylesheet" href="/assets/css/datatables{% if jekyll.environment == "production" %}.min{% endif %}.css" />
108+
<link rel="stylesheet" href="/assets/css/datatables{%- if jekyll.environment == "production" -%}.min{%- endif -%}.css" />
109109
<style>
110110
#main {max-width: revert;}
111111
</style>
112-
<script src="/assets/js/datatables{% if jekyll.environment == "production" %}.min{% endif %}.js"></script>
112+
<script src="/assets/js/datatables{%- if jekyll.environment == "production" -%}.min{%- endif -%}.js"></script>
113+
<script src="/assets/js/utils.js"></script>
113114
<script>
114115
const initialwindowwidth = $(window).width();
115116
const mainContentList = new DataTable("#mainContentList", {
@@ -133,4 +134,43 @@ <h1 class="post-title">{{ page.title | escape }}</h1>
133134
{ "targets": [7], "visible": initialwindowwidth > 820}
134135
]
135136
});
137+
const requestedOrder = getQueryVariable('order'); // e.g. ?order=1.asc
138+
const requestedCols = getQueryVariable('cols'); // e.g. ?cols=0.1.10.11
139+
const requestedPageSize = getQueryVariable('n'); // e.g. ?n=50
140+
const requestedPage = getQueryVariable('p'); // e.g. ?n=50&p=2
141+
if (requestedCols || requestedOrder || requestedPage || requestedPageSize) {
142+
setTimeout(() => {
143+
let needsDraw = false;
144+
if (requestedOrder) {
145+
const order = requestedOrder.split('.');
146+
if (order.length == 2) {
147+
order[0] = parseInt(order[0]);
148+
mainContentList.order(order);
149+
needsDraw = true;
150+
}
151+
}
152+
if (requestedCols) {
153+
const cols = requestedCols.split('.');
154+
mainContentList.columns().every((i) => {
155+
mainContentList.columns(i).visible(cols.includes(i.toString()));
156+
});
157+
}
158+
if (requestedPageSize) {
159+
const ps = parseInt(requestedPageSize);
160+
if (ps > 0) {
161+
mainContentList.page.len(ps);
162+
needsDraw = true;
163+
}
164+
}
165+
if (needsDraw) {
166+
mainContentList.draw();
167+
}
168+
if (requestedPage) {
169+
const p = parseInt(requestedPage);
170+
if (p >= 0) {
171+
mainContentList.page(p).draw(false);
172+
}
173+
}
174+
}, 5);
175+
}
136176
</script>

‎assets/js/utils.js‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,26 @@ var utils = {
7272
'ascii': /^[ -~]+$/
7373
};
7474

75-
function Ranges() {
76-
this.array = [];
77-
}
78-
Ranges.compareStart = function (a, b) { return a[0] > b[0]; };
79-
Ranges.compareEnd = function (a, b) { return a[1] > b[1]; };
80-
Ranges.prototype.dedupeAt = function(index) {
81-
if (index+1<this.array.length && this.array[index][1]+1>=this.array[index+1][0]) {
82-
this.array.splice(index, 2, [this.array[index][0], this.array[index+1][1]]);
75+
class Ranges {
76+
constructor() {
77+
this.array = [];
8378
}
84-
if (index>0 && this.array[index-1][1]+1>=this.array[index][0]) {
85-
this.array.splice(index-1, 2, [this.array[index-1][0], this.array[index][1]]);
79+
static compareStart(a, b) { return a[0] > b[0]; }
80+
static compareEnd(a, b) { return a[1] > b[1]; }
81+
dedupeAt(index) {
82+
if (index + 1 < this.array.length && this.array[index][1] + 1 >= this.array[index + 1][0]) {
83+
this.array.splice(index, 2, [this.array[index][0], this.array[index + 1][1]]);
84+
}
85+
if (index > 0 && this.array[index - 1][1] + 1 >= this.array[index][0]) {
86+
this.array.splice(index - 1, 2, [this.array[index - 1][0], this.array[index][1]]);
87+
}
8688
}
87-
};
88-
Ranges.prototype.add = function(range) {
89-
var si = locationOf(this.array, range, Ranges.compareStart);
90-
var ei = locationOf(this.array, range, Ranges.compareEnd);
91-
if (si > ei) return;
92-
this.array.splice(si, ei-si, range);
93-
this.dedupeAt(si);
94-
};
89+
add(range) {
90+
var si = locationOf(this.array, range, Ranges.compareStart);
91+
var ei = locationOf(this.array, range, Ranges.compareEnd);
92+
if (si > ei) return;
93+
this.array.splice(si, ei - si, range);
94+
this.dedupeAt(si);
95+
}
96+
}
9597

‎scripts/openalexdownloader.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#APIURL="https://api.openalex.org/works?filter=title.search:Gatsby,is_oa:true,is_paratext:false&sort=cited_by_count:desc"
2222
#APIURL = "https://api.openalex.org/works?filter=cites:W1599632106,is_oa:true"
2323

24-
REQUEST_HEADERS = {"User-Agent": "Mozilla/5.0 (Linux; Android 13; SM-A725F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Mobile Safari/537.36"}
24+
REQUEST_HEADERS = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"}
2525

2626
FNAME_MAXLEN = 192 # 126 might be safer
2727

0 commit comments

Comments
 (0)