# Path: engine/conf.py
# PATH_TO_HTML = PATH + "/engine/data/html/"
# 
# PATH_TO_TEMPLATE = PATH + "/themes/" + TEMPLATE + "/notes/"  # don't forget about ending /
# 
# PATH_HOMEPAGE = PATH + "/themes/" + TEMPLATE + "/homepage/head_index.html"
# 
# PATH_TO_MD = PATH + '/notes/'
# 
# PATH_TO_TEMPLATE_HTML = PATH_TO_TEMPLATE + 'head.html'


import os
import time
import re
from engine.conf import PATH_TO_HTML, PATH_TO_TEMPLATE, PATH_HOMEPAGE, PATH_TO_MD, PATH_TO_TEMPLATE_HTML  # noqa
"""geekbook - make index

Get the list of md with sys.stdint.read() and generate html index.html.
The top of the html file is defined here, see the html variable.
The second part is generated in the loop, per md make a link in the index.html.
"""


FLASK_BASED = True


class Index(object):
    def __init__(self):
        pass

    def update(self, list_md):
        """Update the index page

        :param list_md: is a list of your md files"""

        if FLASK_BASED:  # flask mode
            head = open(PATH_TO_TEMPLATE_HTML).read()
            head = head.replace('{{ url_index }}', PATH_TO_HTML + '/' + 'index.html')
            head = head.replace('href="img/', 'href="' + '/img/')
            head = head.replace('="lib/', '="' + '/lib/')
            head = head.replace('="css/', '="' + '/css/')
            head = head.replace('="js/', '="' + '/js/')

            # remove demo content
            head = re.sub(r'<!-- start of demo -->.*<!-- end of demo -->',

# Path: engine/conf.py
# PATH_TO_HTML = PATH + "/engine/data/html/"
# 
# PATH_TO_TEMPLATE = PATH + "/themes/" + TEMPLATE + "/notes/"  # don't forget about ending /
# 
# PATH_HOMEPAGE = PATH + "/themes/" + TEMPLATE + "/homepage/head_index.html"
# 
# PATH_TO_MD = PATH + '/notes/'
# 
# PATH_TO_TEMPLATE_HTML = PATH_TO_TEMPLATE + 'head.html'


# Path: engine/make_index.py
import os
import time
import re
from engine.conf import PATH_TO_HTML, PATH_TO_TEMPLATE, PATH_HOMEPAGE, PATH_TO_MD, PATH_TO_TEMPLATE_HTML  # noqa

"""geekbook - make index

Get the list of md with sys.stdint.read() and generate html index.html.
The top of the html file is defined here, see the html variable.
The second part is generated in the loop, per md make a link in the index.html.
"""


FLASK_BASED = True


class Index(object):
    def __init__(self):
        pass

    def update(self, list_md):
        """Update the index page

        :param list_md: is a list of your md files"""

        if FLASK_BASED:  # flask mode
            head = open(PATH_TO_TEMPLATE_HTML).read()
            head = head.replace('{{ url_index }}', PATH_TO_HTML + '/' + 'index.html')
            head = head.replace('href="img/', 'href="' + '/img/')
            head = head.replace('="lib/', '="' + '/lib/')
            head = head.replace('="css/', '="' + '/css/')
            head = head.replace('="js/', '="' + '/js/')

            # remove demo content
            head = re.sub(r'<!-- start of demo -->.*<!-- end of demo -->',

                          r'', head, flags=re.M | re.DOTALL)