Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticalMike60t committed Jul 22, 2024
1 parent baaaf83 commit 79869b1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
23 changes: 23 additions & 0 deletions components/meta_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<meta http-equiv="Content-Type" content="text/html" />
<meta content="origin" name="referrer" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="keyboard-shortcuts-preference" content="all" />
<meta content="email=no" name="format-detection" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index,follow,max-image-preview:large" />
<meta
property="og:locale"
content="en_US"
xmlns:og="http://opengraphprotocol.org/schema/"
/>
<meta http-equiv="content-language" content="en">
<meta name="color-scheme" content="dark">
<meta property="og:image:type" content="image/png" xmlns:og="http://opengraphprotocol.org/schema/">
<meta property="og:type" content="website" xmlns:og="http://opengraphprotocol.org/schema/">
<meta name="referrer" content="no-referrer-when-downgrade">
<meta name="msapplication-tap-highlight" content="no">
<meta name="msapplication-window" content="width=device-width;height=device-height">
<meta name="google" content="nositelinkssearchbox">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta http-equiv="x-dns-prefetch-control" content="on">
1 change: 1 addition & 0 deletions components/seo_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<base href="/" />
29 changes: 18 additions & 11 deletions generate-directory-index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const fs = require("fs");
const path = require("path");

const rootDir = "./public";

const settings = JSON.parse(fs.readFileSync("settings.json", "utf-8"));
const theme = JSON.parse(fs.readFileSync("theme.json", "utf-8"));
const theme = JSON.parse(fs.readFileSync(settings.files.theme, settings.encoding));

const rootDir = settings.root.directory;

function getFilterList(filePath) {
const fileContent = fs.readFileSync(filePath, "utf-8");
const fileContent = fs.readFileSync(filePath, settings.encoding);
return fileContent
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0);
}

function formatBytes(bytes, decimals = settings.file_size_decimals) {
if (bytes === 0) return "0 Bytes";
function formatBytes(bytes, decimals = settings.size.decimals) {
if (bytes === 0) return settings.size.empty_message;
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = settings.file_sizes;
const sizes = settings.size.sizes;
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}
Expand All @@ -32,7 +32,7 @@ function getDirectoryInfo(dir) {
files.forEach((file) => {
const filePath = path.join(directory, file);
const stats = fs.statSync(filePath);
const filterList = getFilterList(settings.filter_file);
const filterList = getFilterList(settings.files.filter);
if (stats.isDirectory()) {
calculateDirSize(filePath);
} else if (!filterList.includes(file)) {
Expand All @@ -52,7 +52,7 @@ function getDirectoryInfo(dir) {
}

function generateIndex(dir) {
const filterList = getFilterList(settings.filter_file);
const filterList = getFilterList(settings.files.filter);
const files = fs
.readdirSync(dir)
.map((file) => {
Expand All @@ -69,12 +69,17 @@ function generateIndex(dir) {
const parentDir = relativeDir.split("/").slice(0, -1).join("/") || "";
const dirInfo = getDirectoryInfo(dir);

const metaTags = fs.readFileSync(settings.files.meta_tags, settings.encoding);
const seoTags = fs.readFileSync(settings.files.seo_tags, settings.encoding);

const content = `
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${metaTags}
${seoTags}
<title>${relativeDir || "/"}</title>
<style>
* { --color-accent: ${
Expand All @@ -83,7 +88,7 @@ function generateIndex(dir) {
*, ::after, ::before { box-sizing: border-box; color: ${
theme.colors.text.general
}; }
:root { font-family: "Segoe UI", "Segoe UI Bold", "Segoe UI Italic", sans-serif; }
:root { font-family: ${theme.general.font_family}; }
body { background: ${
theme.colors.background.default
}; display: flex; align-items: center; justify-content: flex-start; flex-direction: column; padding: 20px 10px; }
Expand All @@ -101,7 +106,9 @@ function generateIndex(dir) {
}; display: flex; align-items: center; justify-content: flex-start; flex-direction: row; padding: 5px; padding-top: 0; border-bottom: 1px solid var(--color-accent-hover); }
li:hover { background: ${theme.colors.elements.li_file.hover}; }
li:last-child { border-bottom: none; }
a, a span { text-decoration: none; color: var(--color-accent); }
a, a span { text-decoration: ${
theme.general.link.underline === "true" ? "underline" : "none"
}; color: var(--color-accent); }
a:hover, a:hover span { text-decoration: underline; color: var(--color-accent-hover); }
.search { width: 100%; max-width: 600px; padding: 5px 10px; margin-bottom: 20px; border: none; outline: 0; border-radius: ${
theme.element_styles.search.border_radius
Expand Down
18 changes: 15 additions & 3 deletions settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"file_sizes": ["Bytes", "KB", "MB", "GB", "TB"],
"file_size_decimals": 2,
"filter_file": ".exclude"
"root": {
"directory": "./public"
},
"encoding": "utf-8",
"files": {
"theme": "theme.json",
"meta_tags": "components/meta_tags.html",
"seo_tags": "components/seo_tags.html",
"filter": ".exclude"
},
"size": {
"empty_message": "0 Bytes",
"sizes": ["Bytes", "KB", "MB", "GB", "TB"],
"decimals": 2
}
}
8 changes: 8 additions & 0 deletions theme.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"general": {
"text_color": "#fff",
"font_family": "'Segoe UI', 'Segoe UI Bold', 'Segoe UI Italic, sans-serif'",
"link": {
"underline": "true"
},
"border_radius": "5px"
},
"media_query": {
"use_query": "true",
"file_info": {
Expand Down

0 comments on commit 79869b1

Please sign in to comment.