Skip to content

Commit

Permalink
Merge branch 'dev' into fix-adjust-trigger-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjam-slam authored Oct 26, 2024
2 parents 1c27c97 + b790f8a commit 64d937e
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 176 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/publish-docs-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
workflow_dispatch:
pull_request:
branches:
- main
- dev

name: "Publish preview.closeread.dev"
jobs:
publish:
runs-on: ubuntu-latest
steps:
# for accessing this repo's assets in the container
- name: Check out the repo
uses: actions/checkout@v3
# run the container, attaching this repo as a working directory
- name: Run the build process with Docker
uses: addnab/docker-run-action@v3
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
with:
image: stat20/stat20-docker:latest
options: -v ${{ github.workspace }}:/home/rstudio/closeread -e NETLIFY_AUTH_TOKEN=${{ secrets.NETLIFY_AUTH_TOKEN }}
shell: bash
run: |
# exit if any command returns non-zero exit
set -e
cd /home/rstudio/closeread/
# render and publish site
quarto publish netlify docs --id ba6ca24d-1c6b-44b3-b907-16a2bfe5f4b5
67 changes: 22 additions & 45 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,30 @@
# workflow to build docs site and publish to github pages

on:
workflow_dispatch:
push:
branches: main

name: closeread-publish

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false
branches:
- main

name: "Publish closeread.dev"
jobs:
build-docs:
publish:
runs-on: ubuntu-latest
container:
image: ucbscf/berkeley-stat-course:latest
options: --user root
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout closeread repo
uses: actions/checkout@v4

- name: Check Quarto version
run: quarto check
# for accessing this repo's assets in the container
- name: Check out the repo
uses: actions/checkout@v3
# run the container, attaching this repo as a working directory
- name: Run the build process with Docker
uses: addnab/docker-run-action@v3
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
with:
image: stat20/stat20-docker:latest
options: -v ${{ github.workspace }}:/home/rstudio/closeread -e NETLIFY_AUTH_TOKEN=${{ secrets.NETLIFY_AUTH_TOKEN }}
shell: bash
run: |
# exit if any command returns non-zero exit
set -e
- name: Render docs site
run: |
# copy closeread extension into docs
cd docs
mkdir -p _extensions/
cp -Rf ../_extensions/closeread _extensions/
quarto render
shell: bash
cd /home/rstudio/closeread/
- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload docs/ artifact
uses: actions/upload-pages-artifact@v3
with:
path: "./docs/_site"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

# render and publish site
quarto publish netlify docs --id 2a052dac-9a3d-43c1-9f3d-e37e3cb55af2
45 changes: 0 additions & 45 deletions .github/workflows/publish-test-site.yml

This file was deleted.

2 changes: 1 addition & 1 deletion _extensions/closeread/closeread.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

173 changes: 90 additions & 83 deletions _extensions/closeread/closeread.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,101 +58,109 @@ document.addEventListener("DOMContentLoaded", () => {
// collect all sticky elements
const allStickies = Array.from(document.querySelectorAll(".sticky"));


// === Set up scrolling event listeners === //
// scrollama() is accessible because scrollama.min.js is attached via closeread.lua
// scrollama() is accessible because scrollama.min.js is attached
// via closeread.lua
const triggerScrollerConfig = {
step: triggerSelector,
offset: 0.5,
progress: true,
debug: debugMode
}
const progressScrollerConfig = {
step: progressBlockSelector,
offset: 0.5,
progress: true,
debug: debugMode
}

function crTriggerStepEnter(trigger) {
focusedStickyName = trigger.element.getAttribute("data-focus-on")

// update ojs variables
ojsTriggerIndex?.define("crTriggerIndex", trigger.index)
ojsStickyName?.define("crActiveSticky", focusedStickyName)

updateStickies(allStickies, focusedStickyName, trigger)
}

function crTriggerStepProgress(trigger) {
ojsTriggerProgress?.define("crTriggerProgress", trigger.progress)
ojsDirection?.define("crDirection", trigger.direction)
}

function crProgressStepEnter(progressBlock) {
ojsProgressBlock?.define("crProgressBlock", progressBlock.progress)
}

// set up scrollers on document load, and reset them when window zoom changes
// (they seem to misbehave on zoom change: see issue #101)

// primary scroller
const triggerScroller = scrollama();
const triggerScroller = scrollama()
triggerScroller
.setup({
step: triggerSelector,
offset: 0.5,
progress: true,
debug: debugMode
})
.onStepEnter((trigger) => {

focusedStickyName = trigger.element.getAttribute("data-focus-on");

// update ojs variables
ojsTriggerIndex?.define("crTriggerIndex", trigger.index);
ojsStickyName?.define("crActiveSticky", focusedStickyName);

updateStickies(allStickies, focusedStickyName, trigger);

})
.onStepProgress((trigger) => {

// update ojs variables
ojsTriggerProgress?.define("crTriggerProgress", trigger.progress);
ojsDirection?.define("crDirection", trigger.direction);

});
.setup(triggerScrollerConfig)
.onStepEnter(crTriggerStepEnter)
.onStepProgress(crTriggerStepProgress)

// secondary scroller used for making progress blocks
const progressBlockScroller = scrollama();
progressBlockScroller
.setup({
step: progressBlockSelector,
offset: 0.5,
progress: true,
debug: debugMode
})
.onStepProgress((progressBlock) => {
// update ojs variable
ojsProgressBlock?.define("crProgressBlock", progressBlock.progress);
});
// secondary scroller used for making progress blocks
const progressBlockScroller = scrollama()
progressBlockScroller
.setup(progressScrollerConfig)
.onStepProgress(crProgressStepEnter)

window.addEventListener("resize", (event) => {
setTimeout(() => triggerScroller.resize(), 1000)
setTimeout(() => progressBlockScroller.resize(), 1000)
})

// === Hotkey Listeners === //
// Add a listener for scrolling between new triggers
let currentIndex = -1; // Start before the first element

function scrollToNewTrigger(direction) {
const triggers = document.querySelectorAll('.new-trigger');

// Add a listener for scrolling between new triggers
let currentIndex = -1; // Start before the first element
if (triggers.length === 0) return; // do nothing if there's no triggers

function scrollToNewTrigger(direction) {
const triggers = document.querySelectorAll('.new-trigger');

if (triggers.length === 0) return; // do nothing if there's no triggers

if (direction === "next") {
if (currentIndex >= triggers.length - 1) return; // exit if at end
currentIndex += 1;
}

if (direction === "previous") {
if (currentIndex === 0) return; // exit if at start
currentIndex -= 1;
}

const nextTrigger = triggers[currentIndex];
nextTrigger.scrollIntoView({ behavior: 'smooth', block: 'center' });
if (direction === "next") {
if (currentIndex >= triggers.length - 1) return; // exit if at end
currentIndex += 1;
}

document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowRight') {
scrollToNewTrigger("next");
}
if (event.key === 'ArrowLeft') {
scrollToNewTrigger("previous");
}
});
if (direction === "previous") {
if (currentIndex === 0) return; // exit if at start
currentIndex -= 1;
}

const nextTrigger = triggers[currentIndex];
nextTrigger.scrollIntoView({ behavior: 'smooth', block: 'center' });
}

document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowRight') {
scrollToNewTrigger("next");
}
if (event.key === 'ArrowLeft') {
scrollToNewTrigger("previous");
}
});

});

// === Other Hotkey Listeners === //

// toggle presentation mode
document.addEventListener('keydown', (event) => {
const crSections = document.querySelectorAll('.cr-section');
crSections.forEach((el) => {
if (event.key === "p") {
if (el.classList.contains("presentation-mode")) {
el.classList.remove("presentation-mode");
} else {
el.classList.add("presentation-mode");
// toggle presentation mode
document.addEventListener('keydown', (event) => {
const crSections = document.querySelectorAll('.cr-section');
crSections.forEach((el) => {
if (event.key === "p") {
if (el.classList.contains("presentation-mode")) {
el.classList.remove("presentation-mode");
} else {
el.classList.add("presentation-mode");
}
}
}
});
});
});

});


//===============//
Expand Down Expand Up @@ -393,4 +401,3 @@ function getBooleanConfig(metaFlag) {
.querySelector("meta[" + metaFlag + "]")?.getAttribute(metaFlag)
return option === "true"
}

3 changes: 1 addition & 2 deletions _extensions/closeread/closeread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ return {
Para = process_trigger_shortcut
},
{
Div = make_section_layout,
Pandoc = add_classes_to_body
Div = make_section_layout
}
}
File renamed without changes.

0 comments on commit 64d937e

Please sign in to comment.