How can I specify a collection as data within a page, rather than pages within a subfolder? - docpad

As I understand it, docpad utilizes collections in order to easily group and list files that are slated to be rendered (ex. posts, pages). I have a large list of pdf documents (publications from a journal) that I want to specify as a collection so I can write a script that will collect and post them all onto a single page. As far as I can tell, you can only define metadata once on a collection page, and I don't really want to create 50+ pages for each individual publication.
I'm more familiar with the functionality backbone itself uses to specify collections, but I'm not sure how the two (docpad & backbone) interact.

Docpad uses collections to manage the files within a project, not just those that are slated to be rendered. Files in the "document" directory are those that need to be rendered. Those in the "files" directory are those that do not need to be rendered. Those files are simply copied to the "out" dir. What this means is that you can simply place your pdfs in the files dir. This will add your pdfs to the docpad collection and can be accessed in the docpad.coffee file like this:
collections:
# Create a collection called posts
# That contains all the documents that will be going to the out path posts
posts: ->
#getCollection('documents').findAllLive({relativeOutDirPath: 'posts'},[{date:-1}])
# Create a collection called pdfs
# That contains all the files in the pdf directory that originate in the source
# file directory
pdfs: ->
#getCollection('files').findAllLive({relativeOutDirPath: 'pdfs'})
Then create an eco template page to list the pdf files (I would stick this in the pdf folder under documents).
---
layout: 'default'
title: 'My PDF collection'
---
<ul>
<%pdfcollection = #getCollection('pdfs').toJSON()%>
<%for pdf in pdfcollection:%>
<li><%-pdf.url%></li>
<%end%>
</ul>
If you don't want to have the actual pdf files in your website - just display a list - then you could simply type/copy the list into a document and format it as markdown. Something like this:
---
layout: 'default'
title: 'My PDF collection'
---
* [MyPdf](http://pdf.org/) - Pdf about pdfs
* [MyPdf](http://pdf.org/) - Pdf about pdfs
* [MyPdf](http://pdf.org/) - Pdf about pdfs
* [MyPdf](http://pdf.org/) - Pdf about pdfs
Third possibility, which I haven't tested, if you have a list in a text file and really must convert its contents to a collection within Docpad, I would manually create a collection that is seperate from the docpad file collection and assign it as a property of templateData within the docpad.coffee file. This will make the collection available to any page within your site. In the events section of docpad.coffee create a handler for the renderBefore event and open your list text file, loop through it and add the values in each line to your collection.
fs= require('fs')
renderBefore: (opts,next) ->
fs.readFile file, (err,data) ->
arr = data.split('\r\n')
for line in arr
#add to collection etc...

Related

How to avoid :hidden: source file from getting added as bookmarks in Sphinx pdflatex generated pdf file

Using Sphinx documentation generator (with pdflatex), I am creating pdf files and have added links to some of the internal files using label and ref markups like this:
In the called file (xyz.rst)
.. _called-file-label:
In the calling file(abc.rst) I am adding a reference to the label like this:
:ref:`Get Info <called-file-label>`
With the above arrangement, I am able to generate pdf file using pdflatex. However, I find that the called file is also added to the pdf file's bookmarks section which feels somewhat clumsy.
I understand I need to add both the source files in the .. toctree:: section for the hyperlink to appear in the pdf file (I have added the called file using :hidden: directive to prevent the file from showing up in the html document's ToC tree).
My question is: What do I need to do in order that the called file (xyz.rst) does not figure in the bookmarks section of the generated pdf file?
If after .. _called-file-label: label is section:
.. _called-file-label:
Foo Bar
======
Then, the section title "Foo Bar" will always become a bookmark in PDF.
The :hidden: option of toctree is not to hide documents, but to don't show ToC on the place with toctree. I.e. it is to hide toctree, not its documents. Documents in hidden toctree will still be visible in HTML sidebars, PDF bookmarks, etc.
It looks like you need rubric directive. Rubric is like a section, but doesn't make up the table of contents.

Select yaml with drop down

I'm using Github pages to build some pages with text I want to get from yaml files. At present I have two yaml files one each for a different car type. I want to use a drop down in the header to select a car type which will then inform which yaml file to get to repopulate the page with text specific to that car.
I can create the drop down which adds a query string param to the page. I can also iterate through the two yaml files and output specific variables. What I can't figure out is how to use the two together so that the yaml file for the page is informed by the user selection from the dropdown.
Or maybe there is a much better way of doing this??
Github pages uses Jekyll, a static site generator. Your site is built once when you push to your gh-pages branch. After that, your browser is just served the generated HTML pages. All the iterating over your YAML files is done at generation time, not when you request the pages. Since you have no server-side code that is executed when you change your dropdown, you cannot process a query parameter.
Since you cannot process query parameters, you need to place your cars on different URLs. Here's a simple example how to change URLs with a <select> and JavaScript, using the code from this answer:
<select name="" onchange="javascript:location.href = this.value;">
<option value="/mypage/car1/" selected>Car1</option>
<option value="/mypage/car2/">Car2</option>
</select>
Then you just need to generate the HTML pages for each car, located at /mypage/car1/ and /mypage/car2/ respectively. That can be done by using your YAML data as part of the YAML front matter. For example, this could be car1.md:
---
layout: car
permalink: /mypage/car1/
data: # data of your car here
name: my very awesome car
---
Markdown content here (leave empty if you don't need it)
You then create the layout _layouts/car.html and in it, generate the appropriate HTML page. For example, to show the car's name, do something like:
<label>Name:</label> {{page.data.name}}
To avoid JavaScript, you can also create a dropdown menu containing <a> links with pure HTML+CSS.

Indesign data merge on 2 pages with different layout

I would like to have a two page Indesign document. First page has text + image and second page has 2 images. The images should come from a csv file that gets data merged with the Indesign document. Is this achievable. I have only been able to do a data merge when I have one page, but then all pages have the same layout. Is this possible and how do I do it? Thanks.
The solution is to work with XML files (File -> Import XML) instead of CSV. You can make any type of document and put XML objects in text fields, images, ... XML is much more flexible than CSV.
a CSV field that is named #photo1 will link to a file location
column F (for instance)
#photo1
c:\foldername\filename.jpg
c:\folder2name\subfolder\otherfile.png
f:\file3.tiff

Sorted table of contents [TOC] in markup (md)

What is the best practice to list all H1 titles in markup language in sorted list?
If I use [TOC] - order is somehow random. Is there a better way to do it than manually write all links in file?
I am using creole as markup language on BitBucket.
The syntax there is
<<toc />>
which shows all the H1,H2 etc on the pages.
To sort the pages I am putting 1_,2_,3_,... in front of the page titles (not the H1 but the page title). In this way the page names are also numbered and organised.
You can also move files inside different directories and then create a table of content for each directory <>

How to set the positon of table of content when using wkhtmltopdf

I'm using wkhtmltopdf to generate pdf from html pages.
My question is how to set the position of table of content page? It seems that it automatically generated in the beginning of first page. In addition, how to set the css of content of content?
There's an--xsl-style-sheet (file) parameter to wkhtmltopdf, detailed thusly in the extended command line --help (or -H).
A table of content can be added to the document by adding a toc object to
the command line. For example:
wkhtmltopdf toc http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The table of content is generated based on the H tags in the input
documents. First a XML document is generated, then it is converted to
HTML using XSLT.
The generated XML document can be viewed by dumping it to a file using
the --dump-outline switch. For example:
wkhtmltopdf --dump-outline toc.xml http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The XSLT document can be specified using the --xsl-style-sheet switch.
For example:
wkhtmltopdf toc --xsl-style-sheet my.xsl http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The --dump-default-toc-xsl switch can be used to dump the default
XSLT style sheet to stdout. This is a good start for writing your
own style sheet
wkhtmltopdf --dump-default-toc-xsl
The XML document is in the namespace
http://code.google.com/p/wkhtmltopdf/outline
it has a root node called "outline" which contains a number of
"item" nodes. An item can contain any number of item. These are the
outline subsections to the section the item represents. A item node
has the following attributes:
- "title" the name of the section
- "page" the page number the section occurs on
- "link" a URL that links to the section.
- "backLink" the name of the anchor the the section will link back to.
The remaining TOC options only affect the default style sheet
so they will not work when specifying a custom style sheet.
So you define your own XSLT, possibly based on their default, and pass it in. No problemo.
If you want you can even make your customized TOC using a html file. e.g.; if you want to create TOC on names of html file name(s) which will be used in PDF creation (please note that for this you should know names in advance) then you can do this by passing a HTML file say user_toc.html. In this files you can put all your captions/css etc and make a placeholder for file name. This files needs to be parsed with server side code which should fill the file name in placeholder. Now the modified file can be used for TOC.
Example code in Perl:
my $TOCPage = "user_toc.html";
my $file1 = "Testfile1.html";
my $file2 = "Testfile2.html";
my $toc_file_lines;
# Open the user TOC for parsing and write in a buffer
open(FILE, $TOCPage);
read(FILE, $toc_file_lines, -s $TOCPage);
close(FILE);
# Substitute the placeholder with actual file name
$toc_file_lines =~ s/$file_name_placeholder/$file1/;
# Open the same file again and write back the buffer
open(FILE, ">".$TOCPage);
print FILE $toc_file_lines;
close(FILE);
# Linux path for wkhtmltopdf installation
my $wkhtmltopdf_path = '/usr/bin/wkhtmltopdf-i386';
my $command = "$wkhtmltopdf_path --margin-top 20mm --margin-bottom 15mm
--margin-left 15mm --margin-right 15mm
$TOCPage $file1 $file2 $pdf_manual_name";
`$command 2>&1`;
More over you can add a lot other info in TOC like chapter no/total page in chapter so on.
Hope this helps.

Resources