Compare commits

...

2 Commits

Author SHA1 Message Date
crunk 4654ced5e8 change README 23 hours ago
crunk e93a3e3b28 refactoring 24 hours ago
  1. 35
      README.md
  2. 45
      distribusi/distribusi.py
  3. 19
      distribusi/templates/page_template.py

35
README.md

@ -8,6 +8,15 @@ index functions featured in several web servers. It works by traversing the
file system and directory hierarchy to automatically list all the files in the
directory and providing them with html classes and tags for easy styling.
## This distribusi fork powers distribusi-verse
If you want to run distribusi on its own go here: [original](https://git.vvvvvvaria.org/varia/distribusi)
This version is used to power [distribusi-verse](https://git.vvvvvvaria.org/Toolsheds/distribusi-verse) which folds this tool in a webapplication.
To make this work a little easier this version has certain options removed that are handy
and available in the standalone version.
For other distribusi like softwares also checkout [distribusi-go](https://git.coopcloud.tech/decentral1se/distribusi-go)
## Requirements
While a Pip install will pull in Python dependencies, you might need system
@ -85,29 +94,3 @@ The contribution consisted of setting up distribusi.ruruhuis.nl (distribusi is b
> "Individuals collecting fragments each have their own folder. When they put a story, picture, audio, or video file inside a folder, each fragment is assigned a serial number, and gets accumulated in the fragments of hospitality website.The fragments connect us. We hope that we can choose the “nature and attitude” of the medium that mediates our connection."
[https://fragments1444.ink/about.html](source)
## Change It
You'll need to get a copy of the repository and then do an [editable] install:
[editable]: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
```bash
$ git clone https://git.vvvvvvaria.org/varia/distribusi.git && cd distribusi
$ python3 -m venv .venv && source .venv/bin/activate
$ pip install -e .
```
You're then ready to make your changes and experiment with them.
## Release It
You'll need a [PyPi](https://pypi.org/) account and to be added as a maintainer.
Please ask around @ Varia for who has PyPi access.
```
$ # ... change the version number in setup.py ... #
$ pip install twine wheel
$ make publish
```

45
distribusi/distribusi.py

@ -100,19 +100,12 @@ def check_distribusi_index(args, index):
return True
def write_index(args, index, html):
def write_index_html(args, index, html):
with open(index, "w") as index_file:
if args.style:
file_style = open(args.style, "r")
style = file_style.read()
styled_html_head = html_head % style
else:
styled_html_head = html_head % ""
styled_html_head = html_head.format(cssfile=args.style)
index_file.write(styled_html_head)
for line in html:
index_file.write(line + "\n")
index_file.write(html_footer)
@ -187,6 +180,23 @@ def remove_hidden_files_and_folders(dirs, files):
return dirs, files
def is_skipped_file(name, args):
if "index.html" in name:
return True
if name.endswith("_thumbnail.jpg"):
return True
if name.endswith("_alttext.txt"):
return True
if name.endswith("_dv_description.txt"):
return True
if args.style in name:
return True
def distribusify(args, directory): # noqa
for root, dirs, files in os.walk(directory):
html = []
@ -208,16 +218,7 @@ def distribusify(args, directory): # noqa
print("Generating directory listing for", root)
for name in sorted(files):
if "index.html" in name:
continue
if name.endswith("_thumbnail.jpg"):
continue
if name.endswith("_alttext.txt"):
continue
if name.endswith("_dv_description.txt"):
if is_skipped_file(name, args):
continue
full_path = os.path.join(root, name)
@ -271,8 +272,4 @@ def distribusify(args, directory): # noqa
html.insert(0, format_div(args, "dir", "dir", tag, "folder"))
index = os.path.join(root, "index.html")
if os.path.exists(index):
if check_distribusi_index(args, index):
write_index(args, index, html)
elif not os.path.exists(index):
write_index(args, index, html)
write_index_html(args, index, html)

19
distribusi/templates/page_template.py

@ -1,25 +1,16 @@
html_head = """
html_head = '''\
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/distribusi -->
<meta name="generator" content="distribusi" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
.image{max-width: 100%%;}
.pdf object{width:640px;height: 640px;}
.dir::before{content:"📁 ";font-size:18px;}
.filename{display:block;font-family:mono;}
.unkown-file::before{content:"📄 ";font-size:18px;}
div{max-width: 640px;display:inline-block;vertical-align:top;margin:1em;padding:1em;}
video {width:640px;max-height:640px;}
%s
</style>
<link rel="stylesheet" href="{cssfile}" crossorigin="anonymous">
</head>
<body>
"""
'''
html_footer = """
html_footer ='''\
</body>
</html>
"""
'''

Loading…
Cancel
Save