diff --git a/nhentai/utils.py b/nhentai/utils.py
index 4239e91..00e6b00 100644
--- a/nhentai/utils.py
+++ b/nhentai/utils.py
@@ -86,7 +86,53 @@ def generate_main_html(output_dir='.'):
With a link to thier `index.html`.
Default output folder will be the CLI path.
"""
- pass
+ count = 0
+ image_html = ''
+ main = readfile('viewer/main.html')
+ css = readfile('viewer/main.css')
+ element = '\n\
+
\n'
+
+ os.chdir(output_dir) # switch to given dir
+ doujinshi_dirs = next(os.walk('.'))[1]
+ # https://stackoverflow.com/questions/141291/how-to-list-only-top-level-directories-in-python
+
+ for folder in doujinshi_dirs:
+ files = os.listdir(folder)
+ if 'index.html' in files:
+ count += 1
+ else:
+ logger.warning('{} folder does not have index.html, try use --html arg first.'\
+ .format(folder))
+ continue
+ image = files[0] # 001.jpg or 001.png
+ if folder is not None:
+ title = folder.replace('_', ' ')
+ if sys.version_info < (3, 0):
+ title = title.encode('utf-8')
+ else:
+ title = 'nHentai HTML Viewer'
+ image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
+
+ data = main.format(STYLES=css, COUNT=count, PICTURE=image_html)
+ try:
+ if sys.version_info < (3, 0):
+ with open('./main.html', 'w') as f:
+ f.write(data)
+ else:
+ with open('./main.html', 'wb') as f:
+ f.write(data.encode('utf-8'))
+ logger.log(15, 'Main Viewer has been write to \'{0}\''.format('./main.html'))
+ except Exception as e:
+ logger.warning('Writen Main Viewer failed ({})'.format(str(e)))
+ logger.info('==>Process finished.')
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
if doujinshi_obj is not None:
diff --git a/nhentai/viewer/main.html b/nhentai/viewer/main.html
index 3f170a5..d1bf5eb 100644
--- a/nhentai/viewer/main.html
+++ b/nhentai/viewer/main.html
@@ -5,11 +5,9 @@
-
- nHentai
- » Viewer
-
- {STYLE}
+ nHentai » Viewer
+
+
@@ -20,13 +18,6 @@