Prettify
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
const React = require('react')
|
||||
const prettyBytes = require('pretty-bytes')
|
||||
const getFileContentType = require('../utils/getFileContentType')
|
||||
const React = require("react")
|
||||
const prettyBytes = require("pretty-bytes")
|
||||
const getFileContentType = require("../utils/getFileContentType")
|
||||
|
||||
const e = React.createElement
|
||||
|
||||
@ -9,46 +9,46 @@ const formatTime = time => new Date(time).toISOString()
|
||||
const DirectoryListing = ({ dir, entries }) => {
|
||||
const rows = entries.map(({ file, stats }, index) => {
|
||||
const isDir = stats.isDirectory()
|
||||
const href = file + (isDir ? '/' : '')
|
||||
const href = file + (isDir ? "/" : "")
|
||||
|
||||
return e(
|
||||
'tr',
|
||||
{ key: file, className: index % 2 ? 'odd' : 'even' },
|
||||
e('td', null, e('a', { title: file, href }, file)),
|
||||
e('td', null, isDir ? '-' : getFileContentType(file)),
|
||||
e('td', null, isDir ? '-' : prettyBytes(stats.size)),
|
||||
e('td', null, isDir ? '-' : formatTime(stats.mtime))
|
||||
"tr",
|
||||
{ key: file, className: index % 2 ? "odd" : "even" },
|
||||
e("td", null, e("a", { title: file, href }, file)),
|
||||
e("td", null, isDir ? "-" : getFileContentType(file)),
|
||||
e("td", null, isDir ? "-" : prettyBytes(stats.size)),
|
||||
e("td", null, isDir ? "-" : formatTime(stats.mtime))
|
||||
)
|
||||
})
|
||||
|
||||
if (dir !== '/')
|
||||
if (dir !== "/")
|
||||
rows.unshift(
|
||||
e(
|
||||
'tr',
|
||||
{ key: '..', className: 'odd' },
|
||||
e('td', null, e('a', { title: 'Parent directory', href: '../' }, '..')),
|
||||
e('td', null, '-'),
|
||||
e('td', null, '-'),
|
||||
e('td', null, '-')
|
||||
"tr",
|
||||
{ key: "..", className: "odd" },
|
||||
e("td", null, e("a", { title: "Parent directory", href: "../" }, "..")),
|
||||
e("td", null, "-"),
|
||||
e("td", null, "-"),
|
||||
e("td", null, "-")
|
||||
)
|
||||
)
|
||||
|
||||
return e(
|
||||
'table',
|
||||
"table",
|
||||
null,
|
||||
e(
|
||||
'thead',
|
||||
"thead",
|
||||
null,
|
||||
e(
|
||||
'tr',
|
||||
"tr",
|
||||
null,
|
||||
e('th', null, 'Name'),
|
||||
e('th', null, 'Type'),
|
||||
e('th', null, 'Size'),
|
||||
e('th', null, 'Last Modified')
|
||||
e("th", null, "Name"),
|
||||
e("th", null, "Type"),
|
||||
e("th", null, "Size"),
|
||||
e("th", null, "Last Modified")
|
||||
)
|
||||
),
|
||||
e('tbody', null, rows)
|
||||
e("tbody", null, rows)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
const React = require('react')
|
||||
const semver = require('semver')
|
||||
const DirectoryListing = require('./DirectoryListing')
|
||||
const readCSS = require('../utils/readCSS')
|
||||
const React = require("react")
|
||||
const semver = require("semver")
|
||||
const DirectoryListing = require("./DirectoryListing")
|
||||
const readCSS = require("../utils/readCSS")
|
||||
|
||||
const e = React.createElement
|
||||
|
||||
const IndexPageStyle = readCSS(__dirname, 'IndexPage.css')
|
||||
const IndexPageStyle = readCSS(__dirname, "IndexPage.css")
|
||||
const IndexPageScript = `
|
||||
var s = document.getElementById('version'), v = s.value
|
||||
s.onchange = function () {
|
||||
@ -17,37 +17,35 @@ const byVersion = (a, b) => (semver.lt(a, b) ? -1 : semver.gt(a, b) ? 1 : 0)
|
||||
|
||||
const IndexPage = ({ packageInfo, version, dir, entries }) => {
|
||||
const versions = Object.keys(packageInfo.versions).sort(byVersion)
|
||||
const options = versions.map(v =>
|
||||
e('option', { key: v, value: v }, `${packageInfo.name}@${v}`)
|
||||
)
|
||||
const options = versions.map(v => e("option", { key: v, value: v }, `${packageInfo.name}@${v}`))
|
||||
|
||||
return e(
|
||||
'html',
|
||||
"html",
|
||||
null,
|
||||
e(
|
||||
'head',
|
||||
"head",
|
||||
null,
|
||||
e('meta', { charSet: 'utf-8' }),
|
||||
e('title', null, `Index of ${dir}`),
|
||||
e('style', { dangerouslySetInnerHTML: { __html: IndexPageStyle } })
|
||||
e("meta", { charSet: "utf-8" }),
|
||||
e("title", null, `Index of ${dir}`),
|
||||
e("style", { dangerouslySetInnerHTML: { __html: IndexPageStyle } })
|
||||
),
|
||||
e(
|
||||
'body',
|
||||
"body",
|
||||
null,
|
||||
e(
|
||||
'div',
|
||||
{ className: 'content-wrapper' },
|
||||
"div",
|
||||
{ className: "content-wrapper" },
|
||||
e(
|
||||
'div',
|
||||
{ className: 'version-wrapper' },
|
||||
e('select', { id: 'version', defaultValue: version }, options)
|
||||
"div",
|
||||
{ className: "version-wrapper" },
|
||||
e("select", { id: "version", defaultValue: version }, options)
|
||||
),
|
||||
e('h1', null, `Index of ${dir}`),
|
||||
e('script', { dangerouslySetInnerHTML: { __html: IndexPageScript } }),
|
||||
e('hr'),
|
||||
e("h1", null, `Index of ${dir}`),
|
||||
e("script", { dangerouslySetInnerHTML: { __html: IndexPageScript } }),
|
||||
e("hr"),
|
||||
e(DirectoryListing, { dir, entries }),
|
||||
e('hr'),
|
||||
e('address', null, `${packageInfo.name}@${version}`)
|
||||
e("hr"),
|
||||
e("address", null, `${packageInfo.name}@${version}`)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user