Skip to content

Commit

Permalink
Fixed PDF generation scripts so they work correctly now
Browse files Browse the repository at this point in the history
  • Loading branch information
amzn-tomjoht committed Aug 19, 2017
1 parent 97f0f32 commit 0397cb4
Show file tree
Hide file tree
Showing 22 changed files with 7,652 additions and 52 deletions.
4 changes: 2 additions & 2 deletions _data/sidebars/mydoc_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ entries:
type: frontmatter
folderitems:
- title:
url: /titlepage
url: /titlepage.html
output: pdf
type: frontmatter
- title:
url: /tocpage
url: /tocpage.html
output: pdf
type: frontmatter

Expand Down
4 changes: 2 additions & 2 deletions _data/sidebars/product1_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ entries:
type: frontmatter
folderitems:
- title:
url: /titlepage
url: /titlepage.html
output: pdf
type: frontmatter
- title:
url: /tocpage
url: /tocpage.html
output: pdf
type: frontmatter

Expand Down
4 changes: 2 additions & 2 deletions _data/sidebars/product2_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ entries:
type: frontmatter
folderitems:
- title:
url: /titlepage
url: /titlepage.html
output: pdf
type: frontmatter
- title:
url: /tocpage
url: /tocpage.html
output: pdf
type: frontmatter

Expand Down
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/customstyles.css">

<link rel="stylesheet" href="css/boxshadowproperties.css">
<!-- most color styles are extracted out to here -->
<link rel="stylesheet" href="css/theme-blue.css">

Expand Down
7 changes: 1 addition & 6 deletions _includes/head_print.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
<link rel="stylesheet" href="{{ "/css/font-awesome.min.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/bootstrap.min.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/modern-business.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/lavish-bootstrap.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/customstyles.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/theme-green.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/theme-blue.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/syntax.css" | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/printstyles.css" | prepend: site.baseurl }}">

Expand All @@ -27,7 +26,3 @@
return "{{site.print_title}} User Guide";
});
</script>




3 changes: 3 additions & 0 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<li><a href="{{folderitem.external_url}}" target="_blank">{{folderitem.title}}</a></li>
{% elsif page.url == folderitem.url %}
<li class="active"><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
{% elsif folderitem.type == "empty" %}
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>

{% else %}
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
{% endif %}
Expand Down
7,526 changes: 7,525 additions & 1 deletion css/bootstrap.min.css

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions css/boxshadowproperties.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* box-shadow fonts return errors with prince, so extracting here to put in web output only */

#search-demo-container ul#results-container {
box-shadow: 2px 3px 2px #dedede;
}


hr.shaded {
box-shadow: inset 0 6px 6px -6px rgba(0,0,0,0.5);
}

.videoThumbs img {
box-shadow: 2px 2px 1px #f0f0f0;
}

.box {
box-shadow: 2px 2px 4px #dedede;
}

@media (max-width: 1200px) {

.navbar-collapse {
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
5 changes: 0 additions & 5 deletions css/customstyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ p.post-meta {font-size: 80%; color: #777;}
z-index: -1;
width:223px;
border-left: 1px solid #dedede;
box-shadow: 2px 3px 2px #dedede;
}


Expand Down Expand Up @@ -551,7 +550,6 @@ hr.faded {
hr.shaded {
height: 12px;
border: 0;
box-shadow: inset 0 6px 6px -6px rgba(0,0,0,0.5);
margin-top: 70px;
background: white;
width: 100%;
Expand Down Expand Up @@ -904,7 +902,6 @@ span.soft {
.videoThumbs img {
float: left;
margin:15px 15px 15px 0px;
box-shadow: 2px 2px 1px #f0f0f0;
border: 1px solid #dedede;
}

Expand Down Expand Up @@ -1045,7 +1042,6 @@ table thead th code.highlighter-rouge {
.box {
padding: 10px;
border: 1px solid #888;
box-shadow: 2px 2px 4px #dedede;
width: 100px;
height: 80px;
background-color: #f5f5f5;
Expand Down Expand Up @@ -1179,7 +1175,6 @@ h4.panel-title {
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
Expand Down
2 changes: 1 addition & 1 deletion css/printstyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ a[href*="mailto"]::after, a[data-toggle="tooltip"]::after, a[href].noCrossRef::a
.printSubtitle {
font-size: 19pt;
color: #cccccc !important;
front-family: "Grotesque MT Light";
font-family: "Grotesque MT Light";
line-height: 22pt;
letter-spacing: -.5px;
margin-bottom:20px;
Expand Down
8 changes: 6 additions & 2 deletions pages/mydoc/mydoc_content_reuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ folder: mydoc
---

## About content reuse
You can embed content from one file inside another using includes. Put the file containing content you want to reuse (e.g., mypage.html) inside the \_includes/custom folder and then use a tag like this:
You can embed content from one file inside another using includes. Put the file containing content you want to reuse (e.g., mypage.html) inside the \_includes/custom folder and then use a tag like this:

{% raw %}
```
Expand All @@ -20,9 +20,13 @@ You can embed content from one file inside another using includes. Put the file

With content in your \_includes folder, you don't add any frontmatter to these pages because they will be included on other pages already containing frontmatter.

Also, when you include a file, all of the file's contents get included. You can't specify that you only want a specific part of the file included. However, you can use parameters with includes. See the following Jekyll cast for more info about using parameters with includes:
Also, when you include a file, all of the file's contents get included. You can't specify that you only want a specific part of the file included. However, you can use parameters with includes.

{% unless site.output == "pdf" %}
See the following Jekyll cast for more info about using parameters with includes:

<iframe width="640" height="480" src="https://www.youtube.com/embed/kzpGqdEMbIs" frameborder="0" allowfullscreen></iframe>
{% endunless %}

## Page-level variables

Expand Down
36 changes: 18 additions & 18 deletions pages/mydoc/mydoc_generating_pdfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ defaults:
layout: "page_print"
comments: true
search: true

pdf_sidebar: mydoc_sidebar
```
{% include note.html content="Although you're creating a PDF, you must still build an HTML web target before running Prince. Prince will pull from the HTML files and from the file-list for the TOC." %}
Note that the default page layout specified by this configuration file is `page_print`. This layout strips out all the sections that shouldn't appear in the print PDF, such as the sidebar and top navigation bar.

Also note that there's a `output: pdf` toggle in case you want to make some of your content unique to PDF output. For example, you could add conditional logic that checks whether `site.output` is `pdf` or `web`. If it's `pdf`, then include information only for the PDF, and so on. If you're using nav tabs, you'll definitely want to create an alternative experience in the PDF.
Also note that there's a `output: pdf` property in case you want to make some of your content unique to PDF output. For example, you could add conditional logic that checks whether `site.output` is `pdf` or `web`. If it's `pdf`, then include information only for the PDF, and so on. If you're using nav tabs, you'll definitely want to create an alternative experience in the PDF.

In the configuration file, customize the values for the `print_title` and `print_subtitle` that you want. These will appear on the title page of the PDF.

## 3. Make sure your sidebar_doc.yml file has a titlepage.html and tocpage.html
## 3. Make sure your sidebar data file has titlepage.html and tocpage.html entries

There are two template pages in the root directory that are critical to the PDF:

Expand All @@ -74,18 +76,18 @@ There are two template pages in the root directory that are critical to the PDF:
These pages should appear in your sidebar YML file (in this product, mydoc_sidebar.yml):

```yaml
- title:
output: pdf
type: frontmatter
folderitems:
- title:
url: /titlepage.html
output: pdf
type: frontmatter
- title:
url: /tocpage.html
output: pdf
type: frontmatter
folderitems:
- title:
url: /titlepage/
output: pdf
type: frontmatter
- title:
url: /tocpage/
output: pdf
type: frontmatter
```

Leave these pages here in your sidebar. (The `output: pdf` property means they won't appear in your online TOC because the conditional logic of the sidebar.html checks whether `web` is equal to `pdf` or not before including the item in the web version of the content.)
Expand Down Expand Up @@ -288,7 +290,7 @@ This gets the current page:

Because the theme uses JavaScript in the CSS, you have to add the `--javascript` tag in the Prince command (detailed later on this page).

## 5. Customize the PDF script
## 5. Customize and run the PDF script

Duplicate the pdf-mydocf.sh file in the root directory and customize it for your specific configuration files.

Expand All @@ -302,7 +304,7 @@ jekyll serve --detach --config _config.yml,pdfconfigs/config_mydoc_pdf.yml;
echo "done";

echo "Building the PDF ...";
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o _pdf/mydoc.pdf;
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o pdf/mydoc.pdf;
echo "done";
```
Expand Down Expand Up @@ -340,7 +342,7 @@ You can add a download button for your PDF using some Bootstrap button code:

Here's what that looks like:

<a target="_blank" class="noCrossRef" href={{ "pdf/mydoc.pdf"}}"><button type="button" class="btn btn-default" aria-label="Left Align"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> PDF Download</button></a>
<a target="\_blank" class="noCrossRef" href={{ "pdf/mydoc.pdf"}}"><button type="button" class="btn btn-default" aria-label="Left Align"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> PDF Download</button></a>

## JavaScript conflicts

Expand All @@ -356,13 +358,11 @@ You need to conditionalize out any JavaScript from your PDF web output before bu

Then surround the JavaScript with conditional tags like this:

{% raw %}
```
{% unless site.output == "pdf" %}
{% raw %}{% unless site.output == "pdf" %}
javascript content here ...
{% endunless %}
{% endunless %}{% endraw %}
```
{% endraw %}

For more detail about using `unless` in conditional logic, see [Conditional logic][mydoc_conditional_logic]. What this code means is "run this code unless this value is the case."

Expand Down
2 changes: 1 addition & 1 deletion pdf-mydoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ echo "done";

echo "Building the PDF ...";
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o pdf/mydoc.pdf;
echo "done";

echo "Done. Look in the pdf directory to see if it printed successfully."
4 changes: 2 additions & 2 deletions pdf-product1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kill -9 $(ps aux | grep '[j]ekyll' | awk '{print $2}')
clear

echo "Building PDF-friendly HTML site for Product1 ...";
jekyll serve --detach --config _config.yml,pdfconfigs/config_product1_pdf.yml;
bundle exec jekyll serve --detach --config _config.yml,pdfconfigs/config_product1_pdf.yml;
echo "done";

echo "Building the PDF ...";
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o pdf/product1.pdf;
echo "done";
echo "done";
4 changes: 2 additions & 2 deletions pdf-product2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kill -9 $(ps aux | grep '[j]ekyll' | awk '{print $2}')
clear

echo "Building PDF-friendly HTML site for Product2 ...";
jekyll serve --detach --config _config.yml,pdfconfigs/config_product2_pdf.yml;
bundle exec jekyll serve --detach --config _config.yml,pdfconfigs/config_product2_pdf.yml;
echo "done";

echo "Building the PDF ...";
prince --javascript --input-list=_site/pdfconfigs/prince-list.txt -o pdf/product2.pdf;
echo "done";
echo "done";
Binary file modified pdf/mydoc.pdf
Binary file not shown.
Binary file modified pdf/product1.pdf
Binary file not shown.
Binary file modified pdf/product2.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion pdfconfigs/config_mydoc_pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ port: 4010
output: pdf
product: mydoc
print_title: Jekyll theme for documentation — mydoc product
print_subtitle: version 5.0
print_subtitle: version 6.0
output: pdf
defaults:
-
Expand Down
59 changes: 57 additions & 2 deletions pdfconfigs/prince-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ layout: none
search: exclude
---

{% assign sidebar = site.pdf_sidebar %}

{% for entry in sidebar_pdf %}
{% assign sidebar = site.data.sidebars[site.pdf_sidebar].entries %}

{% for entry in sidebar %}

{% for folder in entry.folders %}
{% if folder.output contains "pdf" %}
{% for folderitem in folder.folderitems %}
Expand All @@ -25,3 +27,56 @@ search: exclude
{% endif %}
{% endfor %}
{% endfor %}



{% comment %}

{% assign sidebar = site.data.sidebars[page.sidebar].entries %}

{% for entry in sidebar %}
{% for folder in entry.folders %}
{% if folder.output contains "web" %}
<li>
<a href="#">{{ folder.title }}</a>
<ul>
{% for folderitem in folder.folderitems %}
{% if folderitem.output contains "web" %}
{% if folderitem.external_url %}
<li><a href="{{folderitem.external_url}}" target="_blank">{{folderitem.title}}</a></li>
{% elsif page.url == folderitem.url %}
<li class="active"><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
{% elsif folderitem.type == "empty" %}
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>

{% else %}
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
{% endif %}
{% for subfolders in folderitem.subfolders %}
{% if subfolders.output contains "web" %}
<li class="subfolders">
<a href="#">{{ subfolders.title }}</a>
<ul>
{% for subfolderitem in subfolders.subfolderitems %}
{% if subfolderitem.output contains "web" %}
{% if subfolderitem.external_url %}
<li><a href="{{subfolderitem.external_url}}" target="_blank">{{subfolderitem.title}}</a></li>
{% elsif page.url == subfolderitem.url %}
<li class="active"><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
{% else %}
<li><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
{% endfor %}
{% endcomment %}
2 changes: 1 addition & 1 deletion pdfconfigs/titlepage.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
type: title
search: exclude
permalink: /titlepage/
permalink: /titlepage.html/
---
<div class="printTitleArea">
<div class="printTitle">{{site.print_title}}</div>
Expand Down
Loading

0 comments on commit 0397cb4

Please sign in to comment.