Skip to content
This repository was archived by the owner on Mar 19, 2023. It is now read-only.

Commit 4799496

Browse files
paperbennijayanta525
authored andcommitted
updated apindex
- added bootstrap - new icons - html and python formatting - install script
1 parent 7f3ab79 commit 4799496

20 files changed

+74
-39
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ __Generate a file index for Github Pages__
33

44
![img](https://i.imgur.com/jyZPglj.png)
55

6+
### Quick install
7+
```sh
8+
curl https://raw.githubusercontent.com/jayanta525/apindex/master/install.sh | bash
9+
```
10+
611
### What is this?
712
This is a program that generates `index.html` files in each directory on your server that render the file tree. This is useful for static web servers that need support for file listing. One example of this is Github Pages.
813

apindex.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
VERSION = "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@"
3838
PREFIX = "@CMAKE_INSTALL_PREFIX@"
3939

40+
4041
class Icon:
4142
def __init__(self, file):
4243
self.file = file
4344
self.extensions = []
4445

46+
4547
class ResourceManager:
4648

4749
@staticmethod
@@ -114,9 +116,10 @@ def toHTML(self):
114116
if self.isDir():
115117
fileSize = "-"
116118
else:
117-
fileSize = str(math.floor(os.path.getsize(self.getPath()) / 1000)) + " kB"
119+
fileSize = str(math.floor(
120+
os.path.getsize(self.getPath()) / 1000)) + " kB"
118121
modifyTime = time.strftime('%d-%b-%Y %H:%M',
119-
time.localtime(os.path.getmtime(self.getPath())))
122+
time.localtime(os.path.getmtime(self.getPath())))
120123

121124
return File.STATIC_FILE_HTML.replace("#FILENAME", self.filename) \
122125
.replace("#MODIFIED", modifyTime).replace("#SIZE", str(fileSize)) \
@@ -146,20 +149,23 @@ def getChildren(self):
146149
def getParentDir(self):
147150
return self.root
148151

152+
149153
class IndexWriter:
150154

151155
STATIC_FOOTER = ResourceManager.readFile("footer.template.html") \
152156
.replace("#VERSION", VERSION)
153157

154158
@staticmethod
155-
def writeIndex(startPath, title = None, footer=None):
159+
def writeIndex(startPath, title=None, footer=None):
156160
filesRead = []
157161
dirsRead = []
158162
root = File(startPath)
159163
html = ResourceManager.readFile("index.template.html")
160164

161-
if title is None: title = root.getPathFromRoot()
162-
if footer is None: footer = IndexWriter.STATIC_FOOTER
165+
if title is None:
166+
title = root.getPathFromRoot()
167+
if footer is None:
168+
footer = IndexWriter.STATIC_FOOTER
163169

164170
# fill the details
165171
html = html.replace("#TITLE", title)
@@ -187,15 +193,17 @@ def writeIndex(startPath, title = None, footer=None):
187193
html = html.replace("#GEN_FILES", "".join(str(x) for x in filesRead))
188194

189195
# write the actual index file
190-
print("Writing " + root.getPath() + "/index.html" )
196+
print("Writing " + root.getPath() + "/index.html")
191197
ResourceManager.writeFile(root.getPath() + "/index.html", html)
192198

199+
193200
def main():
194201
if len(sys.argv) <= 1:
195202
print("No root directory specified!")
196203
exit(1)
197204

198205
IndexWriter.writeIndex(sys.argv[1])
199206

200-
if __name__=="__main__":
207+
208+
if __name__ == "__main__":
201209
main()

install.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/bash
2+
3+
echo "installing apindex"
4+
apt-get update
5+
apt-get install cmake python3 -y
6+
git clone --depth=1 https://github.com/jayanta525/apindex.git
7+
cd apindex
8+
cmake . -DCMAKE_INSTALL_PREFIX=/usr
9+
make install
10+
cd ..
11+
rm -rf apindex/

share/apindex/file.template.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<tr>
2-
<td><p style="display: none">#FILENAME</p><img style="margin-right: 5px; max-width: 20px" src="data:image/png;base64, #IMAGE" /><a href="#FILENAME">#FILENAME</a></td>
3-
<td>#MODIFIED</td>
2+
<td>
3+
<p style="display: none">#FILENAME</p><img style="margin-right: 5px; max-width: 20px"
4+
src="data:image/png;base64, #IMAGE" /><a href="#FILENAME">#FILENAME</a>
5+
</td>
46
<td>#SIZE</td>
5-
</tr>
7+
<td>#MODIFIED</td>
8+
</tr>

share/apindex/footer.template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<span style="font-size: 12px">generated by </span><a style="font-size: 12px" href="https://thinkpads.org/projects/apindex">apindex #VERSION</a>
1+
<span style="font-size: 12px">generated by </span><a style="font-size: 12px"
2+
href="https://github.com/jayanta525/apindex" target="_blank">apindex</a>

share/apindex/icons.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22

33
<icons>
4-
4+
55
<icon file="ar.png">
66
<ex>ar</ex>
77
<ex>zip</ex>
@@ -33,6 +33,7 @@
3333

3434
<icon file="patch.png">
3535
<ex>patch</ex>
36+
<ex>diff</ex>
3637
</icon>
3738

3839
<icon file="pdf.png">

share/apindex/img/ar.png

-372 Bytes
Loading

share/apindex/img/back.png

-930 Bytes
Loading

share/apindex/img/conf.png

-2.18 KB
Loading

share/apindex/img/document.png

-1.07 KB
Loading

0 commit comments

Comments
 (0)