Skip to content

Commit b891df9

Browse files
Sanatised json.text to always be in the correct format
1 parent d7bf0ed commit b891df9

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

CONTRIBUTORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Copyright (C) 2024-2025 Calibre-Web Automated contributors
303303
- zhiyue (1 commits)
304304
# Fork Contributors (crocodilestick/calibre-web-automated)
305305

306-
- crocodilestick (812 commits)
306+
- crocodilestick (817 commits)
307307
- jmarmstrong1207 (73 commits)
308308
- demitrix (30 commits)
309309
- sirwolfgang (29 commits)

cps/templates/json.txt

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,59 @@
11
{
2-
"pubdate": "{{entry.pubdate}}",
3-
"title": "{{entry.title}}",
2+
"pubdate": {{ entry.pubdate | string | tojson }},
3+
"title": {{ entry.title | tojson }},
44
"format_metadata": {
55
{% for format in entry.data %}
6-
"{{format.format}}": {
7-
"mtime": "{{entry.last_modified}}",
8-
"size": {{format.uncompressed_size}},
6+
{{ format.format | tojson }}: {
7+
"mtime": {{ entry.last_modified | string | tojson }},
8+
"size": {{ format.uncompressed_size }},
99
"path": ""
1010
}{% if not loop.last %},{% endif %}
1111
{% endfor %}
1212
},
1313
"formats": [
1414
{% for format in entry.data %}
15-
"{{format.format}}"{% if not loop.last %},{% endif %}
15+
{{ format.format | tojson }}{% if not loop.last %},{% endif %}
1616
{% endfor %}
1717
],
1818
"series": null,
19-
"cover": "{{url_for('opds.feed_get_cover', book_id=entry.id)}}",
19+
"cover": {{ url_for('opds.feed_get_cover', book_id=entry.id) | tojson }},
2020
"languages": [
2121
{% for lang in entry.languages %}
22-
"{{lang.lang_code}}"{% if not loop.last %},{% endif %}
22+
{{ lang.lang_code | tojson }}{% if not loop.last %},{% endif %}
2323
{% endfor %}
2424
],
25-
"comments": "{% if entry.comments|length > 0 %}{{entry.comments[0].text.replace('"', '\\"')|safe}}{% endif %}",
25+
"comments": {% if entry.comments|length > 0 %}{{ entry.comments[0].text | tojson }}{% else %}null{% endif %},
2626
"tags": [
2727
{% for tag in entry.tags %}
28-
"{{tag.name}}"{% if not loop.last %},{% endif %}
28+
{{ tag.name | tojson }}{% if not loop.last %},{% endif %}
2929
{% endfor %}
3030
],
31-
"application_id": {{entry.id}},
32-
"series_index": {% if entry.series|length > 0 %}"{{entry.series_index}}"{% else %}null{% endif %},
33-
"last_modified": "{{entry.last_modified}}",
34-
"author_sort": "{{entry.author_sort}}",
35-
"uuid": "{{entry.uuid}}",
36-
"timestamp": "{{entry.timestamp}}",
37-
"thumbnail": "{{url_for('opds.feed_get_cover', book_id=entry.id)}}",
31+
"application_id": {{ entry.id }},
32+
"series_index": {% if entry.series|length > 0 %}{{ entry.series_index | tojson }}{% else %}null{% endif %},
33+
"last_modified": {{ entry.last_modified | string | tojson }},
34+
"author_sort": {{ entry.author_sort | tojson }},
35+
"uuid": {{ entry.uuid | tojson }},
36+
"timestamp": {{ entry.timestamp | string | tojson }},
37+
"thumbnail": {{ url_for('opds.feed_get_cover', book_id=entry.id) | tojson }},
3838
"main_format": {
39-
"{{entry.data[0].format|lower}}": "{{ url_for('opds.opds_download_link', book_id=entry.id, book_format=entry.data[0].format|lower)}}"
39+
{{ entry.data[0].format|lower | tojson }}: {{ url_for('opds.opds_download_link', book_id=entry.id, book_format=entry.data[0].format|lower) | tojson }}
4040
},
41-
"rating":{% if entry.ratings.__len__() > 0 %} "{{entry.ratings[0].rating}}.0"{% else %}0.0{% endif %},
41+
"rating": {% if entry.ratings.__len__() > 0 %}{{ (entry.ratings[0].rating|string + ".0") | tojson }}{% else %}0.0{% endif %},
4242
"authors": [
4343
{% for author in entry.authors %}
44-
"{{author.name.replace('|',',')}}"{% if not loop.last %},{% endif %}
44+
{{ author.name.replace('|',',') | tojson }}{% if not loop.last %},{% endif %}
45+
{% endfor %}
46+
],
47+
"publishers": [
48+
{% for publisher in entry.publishers %}
49+
{{ publisher.name | tojson }}{% if not loop.last %},{% endif %}
4550
{% endfor %}
4651
],
4752
"other_formats": {
4853
{% if entry.data.__len__() > 1 %}
4954
{% for format in entry.data[1:] %}
50-
"{{format.format|lower}}": "{{ url_for('opds.opds_download_link', book_id=entry.id, book_format=format.format|lower)}}"{% if not loop.last %},{% endif %}
55+
{{ format.format|lower | tojson }}: {{ url_for('opds.opds_download_link', book_id=entry.id, book_format=format.format|lower) | tojson }}{% if not loop.last %},{% endif %}
5156
{% endfor %}
5257
{% endif %} },
53-
"title_sort": "{{entry.sort}}"
58+
"title_sort": {{ entry.sort | tojson }}
5459
}

0 commit comments

Comments
 (0)