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:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
# - name: Install nix
|
- name: Install nix
|
||||||
# uses: cachix/install-nix-action@v23
|
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:
|
# with:
|
||||||
# nix_path: "nixpkgs=channel:nixpkgs-unstable"
|
# name: pdf
|
||||||
# extra_nix_config: |
|
# path: '*.pdf'
|
||||||
# experimental-features = nix-command flakes
|
- name: Generate changelog
|
||||||
# access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
run: |
|
||||||
# - name: Show nixpkgs version
|
# Get the previous tag
|
||||||
# run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
git fetch --tags
|
||||||
# - name: Run a command with nix develop
|
PREVIOUS_TAG=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
|
||||||
# run: |
|
# Generate the changelog
|
||||||
# nix develop .#export-pdf --ignore-environment --command bash -c '
|
git log --pretty=format:"%h %s" $PREVIOUS_TAG..HEAD > CHANGELOG
|
||||||
# pnpm install
|
|
||||||
# pnpm export-pdf
|
echo "Changelog from $PREVIOUS_TAG to HEAD:"
|
||||||
# '
|
cat CHANGELOG
|
||||||
# # # For debugging, upload the pdfs as artifacts
|
- name: Release PDF
|
||||||
# # - uses: actions/upload-artifact@v3
|
uses: softprops/action-gh-release@v2
|
||||||
# # with:
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
# # name: pdf
|
with:
|
||||||
# # path: '*.pdf'
|
generate_release_notes: true
|
||||||
# - name: Generate changelog
|
body_path: CHANGELOG
|
||||||
# run: |
|
files: |
|
||||||
# # Get the previous tag
|
nixos-and-flakes-book.pdf
|
||||||
# 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
|
|
||||||
|
@ -17,14 +17,40 @@ if (sidebar) {
|
|||||||
// print routeOrder in terminal
|
// print routeOrder in terminal
|
||||||
console.log("routeOrder: ", routeOrder)
|
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({
|
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
|
routePatterns: ["!/zh/**"], // exclude zh-CN pages
|
||||||
sorter: (pageA, pageB) => {
|
sorter: (pageA, pageB) => {
|
||||||
const aIndex = routeOrder.findIndex((route) => route === pageA.path)
|
// console.log("pageA: ", pageA.path, " pageB: ", pageB.path)
|
||||||
const bIndex = routeOrder.findIndex((route) => route === pageB.path)
|
|
||||||
const index = aIndex - bIndex
|
// remove the locale prefix
|
||||||
// console.log(`sorter: ${pageA.path} vs ${pageB.path} = ${index}`);
|
const pathA = pageA.path.replace("/en/", "/")
|
||||||
return index
|
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