From 0bbbd68dbe7d02a8abf2a58ea826c4a14749d30c Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 2 Feb 2020 10:21:15 +0000 Subject: [PATCH] Init --- .drone.yml | 13 +++++++++ Dockerfile | 8 +++++ assets/header.html | 4 +++ assets/listing.css | 44 ++++++++++++++++++++++++++++ assets/listing.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++ default.conf | 17 +++++++++++ 6 files changed, 159 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 assets/header.html create mode 100644 assets/listing.css create mode 100644 assets/listing.js create mode 100644 default.conf diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..212cf26 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +name: default + +steps: +- name: docker + image: plugins/docker + settings: + registry: r.sbruder.de + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: r.sbruder.de/nginx-index diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..66fe5e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM nginx:alpine + +RUN mkdir /srv/www + +COPY assets /usr/share/nginx/html/assets +COPY default.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 diff --git a/assets/header.html b/assets/header.html new file mode 100644 index 0000000..f7afeb4 --- /dev/null +++ b/assets/header.html @@ -0,0 +1,4 @@ + + + + diff --git a/assets/listing.css b/assets/listing.css new file mode 100644 index 0000000..ce13f98 --- /dev/null +++ b/assets/listing.css @@ -0,0 +1,44 @@ +body, html { + background-color: #fdf6e3; + color: #657b83; + font-family: "TeX Gyre Heros", "Roboto", "Helvetica", "Arial", sans-serif; +} + +tr:nth-child(even) { + background: #eee8d5; +} + +th, td { + padding: 0.1em 0.5em; +} + +th { + text-align: left; + font-weight: bold; + background: #eee8d5; + border-bottom: 1px solid #657b83; +} + +a { + color: #586e75; +} + +a:hover { + color: #073642; +} + +table { + width: 100%; +} + +#search-field { + width: 100%; + border: none; + margin-bottom: 15px; + background: #eee8d5; + color: inherit; +} + +hr { + display: none; +} diff --git a/assets/listing.js b/assets/listing.js new file mode 100644 index 0000000..9ff7365 --- /dev/null +++ b/assets/listing.js @@ -0,0 +1,73 @@ +document.addEventListener('DOMContentLoaded', () => { + function humanFileSize(bytes) { + const thresh = 1024 + if(Math.abs(bytes) < thresh) { + return bytes + ' B' + } + const units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'] + var u = -1 + do { + bytes /= thresh + ++u + } while(Math.abs(bytes) >= thresh && u < units.length - 1) + return bytes.toFixed(1)+' '+units[u] + } + + + function textToA(line) { + let outerElement = document.createElement('div') + outerElement.innerHTML = line + return outerElement.getElementsByTagName('a')[0] + } + + function parseLine(line) { + const href = textToA(line).href + const filename = href.substr(-1) === '/' ? decodeURIComponent(href.split('/').slice(-2, -1)[0]) : decodeURIComponent(href.split('/').pop()) + const size = line.split(' ').pop() + return { + href: href, + filename: filename, + size: size + } + } + + function processLine(line) { + meta = parseLine(line) + return `${meta.filename}${meta.size === '-' ? '-' : humanFileSize(meta.size)}` + } + + const collator = new Intl.Collator('kn', {numeric: true}) + + // transform plain text to table + document.querySelector('pre').outerHTML = '' + document.querySelector('pre').innerHTML + .split('\n') + .filter(line => line !== '') + .filter(line => line !== '../') + .map(processLine) + .sort(collator.compare) + .join('\n') + '
NameSize
..-
' + + let searchField = document.createElement('input') + searchField.id = 'search-field' + searchField.autofocus = true + document.querySelector('body').insertBefore(searchField, document.querySelector('table')) + + const rows = [...document.querySelectorAll('tr:not(:first-child)')] + + document.querySelector('#search-field').addEventListener("input", e => { + const searchValue = e.target.value.toLowerCase() + rows.forEach(row => { + const file = row.querySelector('td:nth-child(1) a').innerText + if (!file.toLowerCase().includes(searchValue)) { + row.style.display = 'none' + } else { + row.style.display = 'table-row' + } + }) + + const visibleRows = rows.filter(row => row.style.display === 'table-row') + if (visibleRows.length === 1) { + window.location = visibleRows[0].querySelector('td a').href + } + }) +}) diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..63767c0 --- /dev/null +++ b/default.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + + access_log off; + + location / { + root /srv/www/; + autoindex on; + autoindex_exact_size on; + add_before_body /__assets/header.html; + } + + location /__assets/ { + alias /usr/share/nginx/html/assets/; + } +}