Skip to content

Commit e24845f

Browse files
authored
chore: PDF build - Add design to Vuln ID, fix blank page and wrong bookmark issue (#996)
* Add design to Vuln ID, fix blank page and wrong bookmark issue * Fix build dependency issue * Update node version in pdf build action * Update node version in pdf build action, Patching set-output commands * Update archived actions to the latest * Update cover page base image
1 parent e237aaf commit e24845f

File tree

6 files changed

+78
-31
lines changed

6 files changed

+78
-31
lines changed

.github/pdf/assets/cover.jpg

-521 KB
Loading

.github/pdf/assets/pdf-style.css

+37-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/pdf/pdf-config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"headerTemplate": "<style>section { margin: 0 15mm; padding:25px 0px 5px 0px; width:100%; font-family: 'system-ui'; font-size: 8px; font-weight: 300; font-style: bold; color:#004391; border-bottom: 1px solid #7DC6E9;}</style><section> <span class=\"pageNumber\" style=\"background-color:#D4F2FD; font-size: 7px; border: 1px solid #D4F2FD; border-radius:50px; padding:5px; color:#0080BD; position:absolute; margin-left:-12.5mm; margin-top:-8mm;\"></span> Web Security Testing Guide {PDF Version}</section>",
1515
"footerTemplate":"<section style=\"display:none;\"></section>",
1616
"printBackground":true,
17-
"preferCSSPageSize":true
17+
"preferCSSPageSize":true,
18+
"timeout": "60000"
1819
},
1920
"stylesheet_encoding": "utf-8"
2021
}

.github/pdf/scripts/make-pdf.sh

+23-6
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ remove_blank_pages () {
8686

8787
# Add page break after each chapter
8888
add_page_break () {
89-
sed -e 's/^# /<div style=\"page-break-after: always\;\"><\/div>\
90-
\
91-
# /' $1
89+
echo '<div style="page-break-after: always;"></div>'
9290
}
9391

9492
# Replace internal markdown Links inside headings with html anchor tags (<a>)
@@ -204,9 +202,23 @@ add_design_to_image_name_tag () {
204202
sed 's/\*\(Figure [0-9.ABCDEF\-]*\: .*\)\*/<div class="image-name-tag-wrap"><span class="image-name-tag">\1<\/span><\/div>/' $1
205203
}
206204

205+
# Add design to the test case id table
206+
add_design_to_test_case_id_table () {
207+
# sed -e '/<table>/,/<th>ID<\/th>/ s/<table>/<table class="test-case-id-table">/' $1
208+
# sed 's/\|ID[.]*\|[\n]\|[-]*\|[\n]\|(WSTG-[A-Z]*-[0-9]*)\|/<table class="test-case-id-table"><thead><tr><th>ID</th></tr></thead><tbody><tr><td>\1</td></tr></tbody></table>/' $1
209+
# sed 's/<table>\s<thead>\s<tr>\s<th>ID<\/th>\s<\/tr>\s<\/thead>/<table class="test-case-id-table"><thead><tr><th>ID<\/th><\/tr>\/thead>/' $1
210+
sed '
211+
/|ID.*|/,/|WSTG-[A-Z]*-[0-9]*|/ {
212+
s/|ID.*|//
213+
s/|[-]*|//
214+
s/|\(WSTG-[A-Z]*-[0-9]*\)|/<ul class="arrowbox"><li class="first">ID<\/li><li class="second">\1<\/li><\/ul>/
215+
}
216+
' $1
217+
}
218+
207219
# Preprocess markdown files to support internal links and image designs
208220
preprocess_markdown_to_support_md_to_pdf () {
209-
cat build/md/$1 | add_page_break | \
221+
cat build/md/$1 | \
210222
replace_internal_markdown_links_with_in_headers_with_html_tags | \
211223
replace_markdown_headers_with_html_tags | \
212224
replace_internal_markdown_links_with_html_tags | \
@@ -226,7 +238,8 @@ preprocess_markdown_to_support_md_to_pdf () {
226238
convert_href_to_lower_case | \
227239
remove_chapter_numbers_from_link | \
228240
add_design_to_images | \
229-
add_design_to_image_name_tag
241+
add_design_to_test_case_id_table | \
242+
{ add_design_to_image_name_tag; add_page_break;}
230243
}
231244

232245
extract_chapter_details_and_page_number_from_pdf () {
@@ -336,7 +349,8 @@ while read line; do
336349
pagenumber=$(($pagenumber+$numberofpages));
337350
numberofpages=0;
338351
headerlevel=0;
339-
352+
sectionTitle1=""
353+
sectionTitle2=""
340354
done < build/chapters.txt;
341355

342356
}
@@ -360,6 +374,9 @@ ls build/md | sort -n | while read x; do preprocess_markdown_to_support_md_to_pd
360374
# Create document body pages by converting Markdown to PDF
361375
md-to-pdf --config-file .github/pdf/pdf-config.json build/wstg-doc-$VERSION.md
362376

377+
# Remove Blank pages from the combined PDF
378+
remove_blank_pages build/wstg-doc-$VERSION.pdf
379+
363380
# Combine Cover page and Document body
364381
pdftk build/cover-$VERSION.pdf build/second-cover-$VERSION.pdf build/wstg-doc-$VERSION.pdf build/back-$VERSION.pdf cat output build/wstg-com-$VERSION.pdf
365382

.github/workflows/build-pdf.yml

+13-21
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
CI: true
2020
steps:
2121
- name: Setup Action
22-
uses: actions/checkout@v2
22+
uses: actions/checkout@v3
2323
- name: Setup Node
24-
uses: actions/setup-node@v1
24+
uses: actions/setup-node@v3
2525
with:
26-
node-version: 12.x
26+
node-version: 16.x
2727
- name: SetUp python
28-
uses: actions/setup-python@v1
28+
uses: actions/setup-python@v4
2929
with:
3030
python-version: '3.x'
3131
- name: Install dependencies
@@ -37,7 +37,7 @@ jobs:
3737
- name: Get Tag Version
3838
if: github.event_name == 'push'
3939
id: vars
40-
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
40+
run: echo "tag=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT
4141
- name: Run Push Build
4242
if: github.event_name == 'push'
4343
run: npm run-script pdfgen -- ${{ steps.vars.outputs.tag }}
@@ -47,28 +47,20 @@ jobs:
4747
- name: Create Release
4848
if: github.event_name == 'push'
4949
id: create_release
50-
uses: actions/create-release@v1
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
uses: ncipollo/[email protected]
5351
with:
54-
tag_name: ${{ github.ref }}
55-
release_name: Release ${{ github.ref }}
52+
name: Release ${{ steps.vars.outputs.tag }}
53+
artifacts: "./build/wstg-${{ steps.vars.outputs.tag }}.pdf"
54+
artifactContentType: application/pdf
55+
artifactErrorsFailBuild: true
5656
draft: false
5757
prerelease: true
58-
- name: Upload Release Asset
59-
if: github.event_name == 'push'
60-
id: upload-release-asset
61-
uses: actions/[email protected]
58+
token: ${{ secrets.GITHUB_TOKEN }}
6259
env:
6360
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
with:
65-
upload_url: ${{ steps.create_release.outputs.upload_url }}
66-
asset_path: ./build/wstg-${{ steps.vars.outputs.tag }}.pdf
67-
asset_name: wstg-${{ steps.vars.outputs.tag }}.pdf
68-
asset_content_type: application/pdf
6961
- name: Attach PDF
7062
if: github.event_name == 'workflow_dispatch'
71-
uses: actions/upload-artifact@v1
63+
uses: actions/upload-artifact@v3
7264
with:
7365
name: wstg-${{ github.event.inputs.version }}.pdf
74-
path: ./build/wstg-${{ github.event.inputs.version }}.pdf
66+
path: ./build/wstg-${{ github.event.inputs.version }}.pdf

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.0.1",
44
"description": "[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/OWASP/wstg/issues) [![OWASP Flagship](https://img.shields.io/badge/owasp-flagship-brightgreen.svg)](https://www.owasp.org/index.php/OWASP_Project_Inventory#tab=Flagship_Projects)",
55
"main": "index.js",
6-
"dependencies": {},
6+
"dependencies": {
7+
"puppeteer": "^19.2.2"
8+
},
79
"devDependencies": {
810
"markdownlint-cli": "^0.31.1"
911
},

0 commit comments

Comments
 (0)