Skip to content

Commit ec3aca0

Browse files
committed
[docs] Add copy buttons to download snippets
1 parent 3ec99f8 commit ec3aca0

5 files changed

Lines changed: 95 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Skip the first 10 seconds of the input video:
4949

5050
More examples can be found throughout [the documentation](https://www.scenedetect.com/docs/latest/cli.html).
5151

52+
**Quick Start (Docker)**:
53+
54+
The same commands work without installing anything using [the official Docker image](https://github.com/Breakthrough/PySceneDetect/pkgs/container/pyscenedetect), which includes all dependencies (`ffmpeg`/`mkvmerge` included). Mount the folder containing your videos and use it for input/output paths:
55+
56+
docker run --rm -v "$(pwd):/files" ghcr.io/breakthrough/pyscenedetect -i /files/video.mp4 split-video -o /files
57+
5258
**Quick Start (Python API)**:
5359

5460
To get started, there is a high level function in the library that performs content-aware scene detection on a video (try it from a Python prompt):

‎website/mkdocs.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ markdown_extensions: [fenced_code]
4141

4242
extra_css:
4343
- style.css
44+
45+
extra_javascript:
46+
- js/helper.js

‎website/pages/download.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ PySceneDetect requires at least Python 3.10 or higher.
1010

1111
<div class="important">
1212
<h4 class="wy-text-neutral"><span class="fa fa-angle-double-down wy-text-info"></span> Standard install (recommended):</h4>
13-
<h3 class="wy-text-neutral"><tt>pip install --upgrade scenedetect</tt></h3>
13+
<pre class="command"><code class="nohighlight">pip install --upgrade scenedetect</code></pre>
1414
<h4 class="wy-text-neutral"><span class="fa fa-angle-down wy-text-info"></span> Headless install (servers, no GUI libs):</h4>
15-
<h3 class="wy-text-neutral"><tt>pip install --upgrade scenedetect-headless</tt></h3>
15+
<pre class="command"><code class="nohighlight">pip install --upgrade scenedetect-headless</code></pre>
1616
</div>
1717

1818
PySceneDetect is available via `pip` as three packages:

‎website/pages/js/helper.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Adds a copy-to-clipboard button to code blocks (the readthedocs theme has no
2+
// built-in equivalent of mkdocs-material's `content.code.copy` feature).
3+
document.addEventListener("DOMContentLoaded", function () {
4+
var blocks = document.querySelectorAll(".rst-content pre");
5+
blocks.forEach(function (pre) {
6+
var code = pre.querySelector("code");
7+
if (!code) {
8+
return;
9+
}
10+
var button = document.createElement("button");
11+
button.className = "copy-btn";
12+
button.type = "button";
13+
button.title = "Copy to clipboard";
14+
button.setAttribute("aria-label", "Copy to clipboard");
15+
button.innerHTML = '<span class="fa fa-clipboard"></span>';
16+
button.addEventListener("click", function () {
17+
navigator.clipboard.writeText(code.innerText.trim()).then(function () {
18+
button.innerHTML = '<span class="fa fa-check"></span>';
19+
button.classList.add("copied");
20+
setTimeout(function () {
21+
button.innerHTML = '<span class="fa fa-clipboard"></span>';
22+
button.classList.remove("copied");
23+
}, 600);
24+
});
25+
});
26+
pre.appendChild(button);
27+
});
28+
});

‎website/pages/style.css‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,59 @@
4141
}
4242
.bm-t1 { background-color: #6da7ec; } /* F1 >= 80 */
4343
.bm-t2 { background-color: #9ec5f4; } /* F1 60-79 */
44-
.bm-t3 { background-color: #cde2fb; } /* F1 40-59 */
44+
.bm-t3 { background-color: #cde2fb; } /* F1 40-59 */
45+
46+
/* Copy-to-clipboard button injected into code blocks by js/helper.js. */
47+
.rst-content pre {
48+
position: relative;
49+
}
50+
.rst-content pre .copy-btn {
51+
position: absolute;
52+
top: 4px;
53+
right: 4px;
54+
padding: 2px 8px;
55+
border: 1px solid transparent;
56+
border-radius: 3px;
57+
background: transparent;
58+
color: #9a9a9a;
59+
cursor: pointer;
60+
font-size: 14px;
61+
line-height: 1.5;
62+
}
63+
.rst-content pre:hover .copy-btn,
64+
.rst-content pre .copy-btn:focus {
65+
border-color: #c4c4c4;
66+
background: rgba(255, 255, 255, 0.8);
67+
color: #404040;
68+
}
69+
.rst-content pre .copy-btn.copied,
70+
.rst-content pre .copy-btn.copied:focus {
71+
color: #27ae60;
72+
}
73+
74+
/* Prominent pip install commands inside the download page "important" divs:
75+
full-width like regular code blocks, but white with larger bold text. */
76+
.rst-content .important h4:has(+ pre.command) {
77+
margin-bottom: 6px;
78+
}
79+
.rst-content .important pre.command {
80+
margin: 0 0 28px 0;
81+
padding: 6px 42px 6px 12px; /* right padding leaves room for the copy button */
82+
background: #fff;
83+
border: 1px solid #e1e4e5;
84+
}
85+
.rst-content .important pre.command code {
86+
font-size: 120%;
87+
font-weight: 700;
88+
color: #404040;
89+
background: transparent;
90+
border: none;
91+
padding: 0;
92+
}
93+
.rst-content .important pre.command:last-child {
94+
margin-bottom: 4px; /* tighten space at the bottom of the box */
95+
}
96+
.rst-content .important pre.command .copy-btn {
97+
top: 50%;
98+
transform: translateY(-50%);
99+
}

0 commit comments

Comments
 (0)