mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-06-21 20:41:25 +02:00
fix: pdf-exporter - fix page sorting, add margin & header/footer (#228)
This commit is contained in:
parent
4b95314112
commit
108ab6e5b0
74
.github/workflows/release-pdf.yml
vendored
74
.github/workflows/release-pdf.yml
vendored
@ -10,41 +10,41 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
# - name: Install nix
|
||||
# uses: cachix/install-nix-action@v23
|
||||
- name: Install nix
|
||||
uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
nix_path: "nixpkgs=channel:nixpkgs-unstable"
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Show nixpkgs version
|
||||
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
||||
- name: Run a command with nix develop
|
||||
run: |
|
||||
nix develop .#export-pdf --ignore-environment --command bash -c '
|
||||
pnpm install
|
||||
pnpm export-pdf
|
||||
'
|
||||
# # For debugging, upload the pdfs as artifacts
|
||||
# - uses: actions/upload-artifact@v3
|
||||
# with:
|
||||
# nix_path: "nixpkgs=channel:nixpkgs-unstable"
|
||||
# extra_nix_config: |
|
||||
# experimental-features = nix-command flakes
|
||||
# access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||
# - name: Show nixpkgs version
|
||||
# run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
||||
# - name: Run a command with nix develop
|
||||
# run: |
|
||||
# nix develop .#export-pdf --ignore-environment --command bash -c '
|
||||
# pnpm install
|
||||
# pnpm export-pdf
|
||||
# '
|
||||
# # # For debugging, upload the pdfs as artifacts
|
||||
# # - uses: actions/upload-artifact@v3
|
||||
# # with:
|
||||
# # name: pdf
|
||||
# # path: '*.pdf'
|
||||
# - name: Generate changelog
|
||||
# run: |
|
||||
# # Get the previous tag
|
||||
# git fetch --tags
|
||||
# PREVIOUS_TAG=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
|
||||
# # Generate the changelog
|
||||
# git log --pretty=format:"%h %s" $PREVIOUS_TAG..HEAD > CHANGELOG
|
||||
#
|
||||
# echo "Changelog from $PREVIOUS_TAG to HEAD:"
|
||||
# cat CHANGELOG
|
||||
# - name: Release PDF
|
||||
# uses: softprops/action-gh-release@v1
|
||||
# if: startsWith(github.ref, 'refs/tags/')
|
||||
# with:
|
||||
# generate_release_notes: true
|
||||
# body_path: CHANGELOG
|
||||
# files: |
|
||||
# nixos-and-flakes-book.pdf
|
||||
# name: pdf
|
||||
# path: '*.pdf'
|
||||
- name: Generate changelog
|
||||
run: |
|
||||
# Get the previous tag
|
||||
git fetch --tags
|
||||
PREVIOUS_TAG=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
|
||||
# Generate the changelog
|
||||
git log --pretty=format:"%h %s" $PREVIOUS_TAG..HEAD > CHANGELOG
|
||||
|
||||
echo "Changelog from $PREVIOUS_TAG to HEAD:"
|
||||
cat CHANGELOG
|
||||
- name: Release PDF
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
generate_release_notes: true
|
||||
body_path: CHANGELOG
|
||||
files: |
|
||||
nixos-and-flakes-book.pdf
|
||||
|
@ -17,14 +17,40 @@ if (sidebar) {
|
||||
// print routeOrder in terminal
|
||||
console.log("routeOrder: ", routeOrder)
|
||||
|
||||
const headerTemplate = `<div style="margin-top: -0.4cm; height: 70%; width: 100%; display: flex; justify-content: center; align-items: center; color: lightgray; border-bottom: solid lightgray 1px; font-size: 10px;">
|
||||
<span class="title"></span>
|
||||
</div>`
|
||||
|
||||
const footerTemplate = `<div style="margin-bottom: -0.4cm; height: 70%; width: 100%; display: flex; justify-content: flex-start; align-items: center; color: lightgray; border-top: solid lightgray 1px; font-size: 10px;">
|
||||
<span style="margin-left: 15px;" class="url"></span>
|
||||
</div>`
|
||||
|
||||
export default defineUserConfig({
|
||||
urlOrigin: "https://nixos-and-flakes.thiscute.world/",
|
||||
pdfOptions: {
|
||||
format: "A4",
|
||||
printBackground: true,
|
||||
displayHeaderFooter: true,
|
||||
headerTemplate,
|
||||
footerTemplate,
|
||||
margin: {
|
||||
bottom: 60,
|
||||
left: 25,
|
||||
right: 25,
|
||||
top: 60,
|
||||
},
|
||||
},
|
||||
|
||||
routePatterns: ["!/zh/**"], // exclude zh-CN pages
|
||||
sorter: (pageA, pageB) => {
|
||||
const aIndex = routeOrder.findIndex((route) => route === pageA.path)
|
||||
const bIndex = routeOrder.findIndex((route) => route === pageB.path)
|
||||
const index = aIndex - bIndex
|
||||
// console.log(`sorter: ${pageA.path} vs ${pageB.path} = ${index}`);
|
||||
return index
|
||||
// console.log("pageA: ", pageA.path, " pageB: ", pageB.path)
|
||||
|
||||
// remove the locale prefix
|
||||
const pathA = pageA.path.replace("/en/", "/")
|
||||
const pathB = pageB.path.replace("/en/", "/")
|
||||
// compare
|
||||
const aIndex = routeOrder.findIndex((route) => route === pathA)
|
||||
const bIndex = routeOrder.findIndex((route) => route === pathB)
|
||||
return aIndex - bIndex
|
||||
},
|
||||
urlOrigin: "https://nixos-and-flakes.thiscute.world/",
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user