Beispiel #1
0
    def process(self):
        self.active = True

        # substitute and process plugin content
        self.process_plugin_content()
        # sets:
        # - self.page_body_subst
        # - self.cdata_blocks
        # - self.plugin_blocks
        # - self.plugin_blocks_pdf
        # - self.plugin_pandoc_opts

        # primary navigation
        self.nav_primary = gen_nav_primary(self.branch)

        # page list
        self.nav_pagelist = gen_nav_pagelist(self.subpath)

        # prepare pandoc opts
        self.prepare_pandoc()

        # process through pandoc
        self.page_html_subst = pandoc_pipe(self.page_body_subst,
                                           self.pandoc_opts)

        # back-substitute plugin content
        if self.plugin_blocks != []:
            self.page_html = back_substitute(self.page_html_subst,
                                             self.plugin_blocks)
        else:
            self.page_html = self.page_html_subst

        self.active = False
Beispiel #2
0
    def process(self):
        self.active = True

        # substitute and process plugin content
        self.process_plugin_content()
        # sets:
        # - self.page_body_subst
        # - self.cdata_blocks
        # - self.plugin_blocks
        # - self.plugin_blocks_pdf
        # - self.plugin_pandoc_opts

        # primary navigation
        self.nav_primary = gen_nav_primary(self.branch)

        # page list
        self.nav_pagelist = gen_nav_pagelist(self.subpath)

        # prepare pandoc opts
        self.prepare_pandoc()

        # process through pandoc
        self.page_html_subst = pandoc_pipe(self.page_body_subst,
                                           self.pandoc_opts)

        # back-substitute plugin content
        if self.plugin_blocks != []:
            self.page_html = back_substitute(self.page_html_subst,
                                             self.plugin_blocks)
        else:
            self.page_html = self.page_html_subst

        self.active = False
Beispiel #3
0
    def process_body(self):
        # substitute and process plugin content
        self.process_plugin_content()

        # process through pandoc
        pandoc_opts = [ '--to=html5' ]

        self.page_html_subst = pandoc_pipe(self.body_md_subst, pandoc_opts)

        # back-substitute plugin content
        if self.plugin_blocks != []:
            self.variables['body'] = back_substitute( self.page_html_subst,
                                                      self.plugin_blocks )
        else:
            self.variables['body'] = self.page_html_subst
Beispiel #4
0
def latest_articles(branch):

    # get all pages
    pages = []
    for repo in branch.repos:
        for subpath in repo.subpaths:
            for page in subpath.pages:
                if not page.date_obj == config.BADDATE_STR:
                    pages.append(page)

    # sort after date
    pages.sort(key=lambda k: k.date_obj.timestamp())
    pages.reverse()
    for page in pages:
        print("PAGE DATE" , page.date_obj, "PAGE NAME", page.out_filepath)    

    pandoc_opts = [ '--to=json',
                    '--template='+ARTICLE_PREVIEW_TEMPLATE,
                    '--filter='+PANDOC_FILTER_IMG_PATH ]
    latest_articles_html = ""
    for page in pages[:NUM_OF_ARTICLES]:
        lines = []
        for line in page.page_body_md.splitlines()[:NUM_OF_PREVIEW_LINES]:
            lines.append(line)
        body_part_md = '\n'.join(line for line in lines)

        print("BODY PART MD", body_part_md)

        for index, tb_value in enumerate(page.tb_values):
            pandoc_opts.append('--variable='+config.TB_LINES[index]+':'+tb_value)
        body_part_html = pandoc_pipe(body_part_md, pandoc_opts)

        print("BODY_PART_HTML", body_part_html)

        # replace the placeholder by the actual path...
        



    return "", ""
Beispiel #5
0
def latest_articles(branch):

    # get all pages
    pages = []
    for repo in branch.repos:
        for subpath in repo.subpaths:
            for page in subpath.pages:
                if not page.date_obj == config.BADDATE_STR:
                    pages.append(page)

    # sort after date
    pages.sort(key=lambda k: k.date_obj.timestamp())
    pages.reverse()
    for page in pages:
        print("PAGE DATE", page.date_obj, "PAGE NAME", page.out_filepath)

    pandoc_opts = [
        '--to=json', '--template=' + ARTICLE_PREVIEW_TEMPLATE,
        '--filter=' + PANDOC_FILTER_IMG_PATH
    ]
    latest_articles_html = ""
    for page in pages[:NUM_OF_ARTICLES]:
        lines = []
        for line in page.page_body_md.splitlines()[:NUM_OF_PREVIEW_LINES]:
            lines.append(line)
        body_part_md = '\n'.join(line for line in lines)

        print("BODY PART MD", body_part_md)

        for index, tb_value in enumerate(page.tb_values):
            pandoc_opts.append('--variable=' + config.TB_LINES[index] + ':' +
                               tb_value)
        body_part_html = pandoc_pipe(body_part_md, pandoc_opts)

        print("BODY_PART_HTML", body_part_html)

        # replace the placeholder by the actual path...

    return "", ""
Beispiel #6
0
def gallery(subdir, plugin_in):
    gallery_dir = plugin_in
    gallery_name = GALLERY_PREFIX + os.path.basename(gallery_dir)

    # check if the directory exists
    if os.path.isdir(plugin_in):
        print("Inserting gallery:", gallery_dir)
        pass
    else:
        dir_not_found_error = "GALLERY plugin error: Directory " + gallery_dir + " not found."
        print(dir_not_found_error)
        return dir_not_found_error, dir_not_found_error

    ## Handle the images:
    # set the out dir
    images_out_dir = os.path.join(config.PUBLISH_DIR, subdir, gallery_name)

    # get the images
    filelist = os.listdir(gallery_dir)

    image_list = []
    for file in filelist:
        if file.endswith(".jpg"):
            image_list.append(file)
        elif file.endswith(".png"):
            image_list.append(file)

    # make the thumbs and main images
    if not os.path.isdir(images_out_dir):
        os.makedirs(images_out_dir)

    thumbs_list = []
    #main_images_list=[]
    for image in image_list:
        # set the prefix, infile, outfile
        # (make lists for later handling)
        thumb_name = THUMB_IMAGE_PREFIX + image
        thumbs_list.append(thumb_name)
        main_image_name = MAIN_IMAGE_PREFIX + image
        #main_images_list.append(main_image_name)

        image_in_path = os.path.join(gallery_dir, image)
        thumb_out_path = os.path.join(images_out_dir, thumb_name)
        main_image_out_path = os.path.join(images_out_dir, main_image_name)

        if not os.path.isfile(thumb_out_path):
            convert_image(image_in_path, THUMB_IMAGE_WIDTH, thumb_out_path)

        if not os.path.isfile(main_image_out_path):
            convert_image(image_in_path, MAIN_IMAGE_WIDTH, main_image_out_path)

    ## Make the HTML:
    # make the thumb lines
    # sort and reverse order for pandoc
    thumbs_list.sort()
    thumbs_list.reverse()
    thumb_lines = []
    for thumb in thumbs_list:
        img_src = os.path.join(gallery_name, thumb)
        # image alt text should be inserted from db (text file) here
        img_alt = ''
        # writing html here to speed up things...
        thumb_line = '<img src="{}" alt="{}" onclick="change_image(this, parentNode.parentNode.id)" style="width:auto;"/>'.format(
            img_src, img_alt)

        thumb_lines.append(thumb_line)

    # make the gallery
    opts = ['--template', GALLERY_TEMPLATE]

    opts.append('--variable=gallery-name:' + gallery_name)

    for line in thumb_lines:
        opts.append('--variable=thumb-img-line:' + line)

    gallery_html = pandoc_pipe('', opts)

    # output for PDF production
    if config.PRODUCE_PDF:
        # returning raw content + remark
        #pdf_md = "[[ GALLERY ] [ "+plugin_in+" ]  \n(Gallery plugin, PDF output not yet supported.)\n"
        # (debug-print)
        #print("pdf md: ", pdf_md)

        # inserting images
        # (sort list)
        image_list.sort()

        # (MD)
        md_text = "Images  \n"

        # (adding an MD image reference for every image)
        for image in image_list:

            # (make images)
            image_in_path = os.path.join(gallery_dir, image)
            pdf_image_name = PDF_IMAGE_PREFIX + image
            pdf_image_out_path = os.path.join(images_out_dir, pdf_image_name)
            if not os.path.isfile(pdf_image_out_path):
                convert_image(image_in_path, PDF_IMAGE_WIDTH,
                              pdf_image_out_path)

            # (we need the absolute path for the PDF production)
            cwd = os.getcwd()
            images_out_dir_abs = os.path.join(cwd, images_out_dir)

            img_name = PDF_IMAGE_PREFIX + image

            img_src = os.path.join(images_out_dir_abs, img_name)
            img_alt = ''

            md_ref = "![ {alt} ]({src})\n".format(alt=img_alt, src=img_src)
            md_text = md_text + md_ref

        pdf_md = md_text

    else:
        pdf_md = ""

    return gallery_html, pdf_md
Beispiel #7
0
def insert_file(subdir, plugin_in):
    # get the content type and path or filename
    fields = plugin_in.split(',')
    type = fields[0]

    file_in = fields[-1].strip()

    # find out where the file lies
    if not os.path.isabs(file_in):
        filepath = os.path.join(config.CONTENT_DIR, subdir, file_in)

    else:
        filepath = file_in

    # (debug-info)
    #print('Filepath:', filepath)

    # check if it exists
    if os.path.isfile(filepath):
        print("Inserting file:", filepath)
        pass
    else:
        # could make a nicer html error here...
        # and maybe a try/except statement would be better but (?)
        file_not_found_error = "INSERTFILE plugin error: File (" + filepath + ") not found."
        print(file_not_found_error)
        return file_not_found_error, file_not_found_error

    # read the file
    file_op = open(filepath, 'r')
    file_content = file_op.read()
    file_op.close()

    # extract additional fields
    add_fields = ''
    if len(fields) > 2:
        for field in fields[1:-1]:
            add_fields = ' ' + field.strip() + add_fields

    # append markdown code syntax and type and additional fields
    markdown_code_pre = '\n\n~~~ {.' + type + add_fields + ' .' + INSERT_FILE_CLASS + '}'
    markdown_code_post = '~~~\n\n'

    file_content_md = markdown_code_pre + '\n' + file_content + '\n' + markdown_code_post

    # process through pandoc
    file_content_html = pandoc_pipe(file_content_md, [])

    # insert a title block (table, already html formatted)
    filename = os.path.basename(filepath)
    dir_path = os.path.dirname(file_in)
    if dir_path == '':
        dir_path = '.'
    title_line = '<table class="InsertFileTitle"><tr><td class="Titlefield">Filename:</td><td class="Textfield" title="Inserted from: ' + dir_path + '">' + filename + '</td></tr></table>'

    file_content_html_title = title_line + '\n' + file_content_html

    # PDF production
    if config.PRODUCE_PDF:
        # create a title
        title_md = "File: " + filename + "\n"
        # (debug)
        #file_content_md = plugin_in
        file_content_md = title_md + file_content_md
        # (debug-print)
        #print("file_content_md: ", file_content_md)

    else:
        file_content_md = ""
        # (debug-print)
        #print("md empty...")

    return file_content_html_title, file_content_md
Beispiel #8
0
def insert_file(subdir, plugin_in):
	# get the content type and path or filename
	fields=plugin_in.split(',')
	type=fields[0]
	
	file_in=fields[-1].strip()
	
	# find out where the file lies
	if not os.path.isabs(file_in):
		filepath=os.path.join(config.CONTENT_DIR, subdir, file_in)
	
	else:
		filepath=file_in
	
	# (debug-info)
	#print('Filepath:', filepath)
	
	# check if it exists
	if os.path.isfile(filepath):
		print("Inserting file:", filepath)
		pass
	else:
		# could make a nicer html error here...
		# and maybe a try/except statement would be better but (?)
		file_not_found_error="INSERTFILE plugin error: File ("+filepath+") not found."
		print(file_not_found_error)
		return file_not_found_error, file_not_found_error
	
	# read the file
	file_op=open(filepath, 'r')
	file_content=file_op.read()
	file_op.close()
	
	# extract additional fields
	add_fields=''
	if len(fields) > 2:
		for field in fields[1:-1]:
			add_fields=' '+field.strip()+add_fields
	
	# append markdown code syntax and type and additional fields
	markdown_code_pre='\n\n~~~ {.'+type+add_fields+' .'+INSERT_FILE_CLASS+'}'
	markdown_code_post='~~~\n\n'
	
	file_content_md=markdown_code_pre+'\n'+file_content+'\n'+markdown_code_post
	
	# process through pandoc
	file_content_html=pandoc_pipe(file_content_md, [])
	
	# insert a title block (table, already html formatted)
	filename=os.path.basename(filepath)
	dir_path=os.path.dirname(file_in)
	if dir_path == '':
		dir_path='.'
	title_line='<table class="InsertFileTitle"><tr><td class="Titlefield">Filename:</td><td class="Textfield" title="Inserted from: '+dir_path+'">'+filename+'</td></tr></table>'
	
	file_content_html_title=title_line+'\n'+file_content_html
	
	# PDF production
	if config.PRODUCE_PDF:
		# create a title
		title_md = "File: "+filename+"\n"
		# (debug)
		#file_content_md = plugin_in
		file_content_md = title_md+file_content_md
		# (debug-print)
		#print("file_content_md: ", file_content_md)
		
	else:
		file_content_md = ""
		# (debug-print)
		#print("md empty...")
	
	return file_content_html_title, file_content_md
Beispiel #9
0
def gallery(subdir, plugin_in):
    gallery_dir = plugin_in
    gallery_name = GALLERY_PREFIX + os.path.basename(gallery_dir)

    # check if the directory exists
    if os.path.isdir(plugin_in):
        print("Inserting gallery:", gallery_dir)
        pass
    else:
        dir_not_found_error = "GALLERY plugin error: Directory " + gallery_dir + " not found."
        print(dir_not_found_error)
        return dir_not_found_error, dir_not_found_error

        ## Handle the images:
        # set the out dir
    images_out_dir = os.path.join(config.PUBLISH_DIR, subdir, gallery_name)

    # get the images
    filelist = os.listdir(gallery_dir)

    image_list = []
    for file in filelist:
        if file.endswith(".jpg"):
            image_list.append(file)
        elif file.endswith(".png"):
            image_list.append(file)

            # make the thumbs and main images
    if not os.path.isdir(images_out_dir):
        os.makedirs(images_out_dir)

    thumbs_list = []
    # main_images_list=[]
    for image in image_list:
        # set the prefix, infile, outfile
        # (make lists for later handling)
        thumb_name = THUMB_IMAGE_PREFIX + image
        thumbs_list.append(thumb_name)
        main_image_name = MAIN_IMAGE_PREFIX + image
        # main_images_list.append(main_image_name)

        image_in_path = os.path.join(gallery_dir, image)
        thumb_out_path = os.path.join(images_out_dir, thumb_name)
        main_image_out_path = os.path.join(images_out_dir, main_image_name)

        if not os.path.isfile(thumb_out_path):
            convert_image(image_in_path, THUMB_IMAGE_WIDTH, thumb_out_path)

        if not os.path.isfile(main_image_out_path):
            convert_image(image_in_path, MAIN_IMAGE_WIDTH, main_image_out_path)

            ## Make the HTML:
            # make the thumb lines
            # sort and reverse order for pandoc
    thumbs_list.sort()
    thumbs_list.reverse()
    thumb_lines = []
    for thumb in thumbs_list:
        img_src = os.path.join(gallery_name, thumb)
        # image alt text should be inserted from db (text file) here
        img_alt = ""
        # writing html here to speed up things...
        thumb_line = '<img src="{}" alt="{}" onclick="change_image(this, parentNode.parentNode.id)" style="width:auto;"/>'.format(
            img_src, img_alt
        )

        thumb_lines.append(thumb_line)

        # make the gallery
    opts = ["--template", GALLERY_TEMPLATE]

    opts.append("--variable=gallery-name:" + gallery_name)

    for line in thumb_lines:
        opts.append("--variable=thumb-img-line:" + line)

    gallery_html = pandoc_pipe("", opts)

    # output for PDF production
    if config.PRODUCE_PDF:
        # returning raw content + remark
        # pdf_md = "[[ GALLERY ] [ "+plugin_in+" ]  \n(Gallery plugin, PDF output not yet supported.)\n"
        # (debug-print)
        # print("pdf md: ", pdf_md)

        # inserting images
        # (sort list)
        image_list.sort()

        # (MD)
        md_text = "Images  \n"

        # (adding an MD image reference for every image)
        for image in image_list:

            # (make images)
            image_in_path = os.path.join(gallery_dir, image)
            pdf_image_name = PDF_IMAGE_PREFIX + image
            pdf_image_out_path = os.path.join(images_out_dir, pdf_image_name)
            if not os.path.isfile(pdf_image_out_path):
                convert_image(image_in_path, PDF_IMAGE_WIDTH, pdf_image_out_path)

                # (we need the absolute path for the PDF production)
            cwd = os.getcwd()
            images_out_dir_abs = os.path.join(cwd, images_out_dir)

            img_name = PDF_IMAGE_PREFIX + image

            img_src = os.path.join(images_out_dir_abs, img_name)
            img_alt = ""

            md_ref = "![ {alt} ]({src})\n".format(alt=img_alt, src=img_src)
            md_text = md_text + md_ref

        pdf_md = md_text

    else:
        pdf_md = ""

    return gallery_html, pdf_md