diff --git a/static/resources_list.txt b/static/resources_list.txt index d31c323ba..6c0570442 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -19,6 +19,7 @@ skin/jquery-ui/jquery-ui.theme.min.css skin/jquery-ui/jquery-ui.min.css skin/caret.png skin/taskbar.js +skin/index.js skin/taskbar.css skin/block_external.js templates/search_result.html diff --git a/static/skin/index.js b/static/skin/index.js new file mode 100644 index 000000000..38d39e5b2 --- /dev/null +++ b/static/skin/index.js @@ -0,0 +1,32 @@ +window.onload = async (event) => { + const root = $( `link[type='root']` ).attr("href"); + await fetch(`${root}/catalog/search`) + .then(async (resp) => { + const data = new window.DOMParser().parseFromString(await resp.text(), 'application/xml'); + const entries = data.querySelectorAll("entry"); + displayBooks(entries); + }); +}; + + +function getInnerHtml(node, query) { + return node.querySelector(query).innerHTML; +} + +function displayBooks(books) { + let bookHtml = ''; + books.forEach((book) => { + const link = book.querySelector('link').getAttribute('href'); + const title = getInnerHtml(book, 'title'); + const description = getInnerHtml(book, 'summary'); + + bookHtml += `
+
+
${title}
+
${description}
+
${getInnerHtml(book, 'articleCount')} articles, ${getInnerHtml(book, 'mediaCount')} medias
+
+
`; + }); + document.querySelector('.book__list').innerHTML = bookHtml; +} \ No newline at end of file diff --git a/static/templates/index.html b/static/templates/index.html index dc355aa63..7ad31bd9e 100644 --- a/static/templates/index.html +++ b/static/templates/index.html @@ -40,22 +40,12 @@ } .book__info { color: #777; font-weight: bold; font-size: 13px; line-height: 1em; } - +
-
- {{#books}} -
-
-
{{title}}
-
{{description}}
-
{{articleCount}} articles, {{mediaCount}} medias
-
-
- {{/books}} -
+