diff --git a/Project.toml b/Project.toml index aa1976fe..f30aa453 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PlutoUI" uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8" authors = ["Fons van der Plas "] -version = "0.7.74" +version = "0.7.75" [deps] AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150" diff --git a/src/PlutoUI.jl b/src/PlutoUI.jl index a471df61..eabc0ad5 100644 --- a/src/PlutoUI.jl +++ b/src/PlutoUI.jl @@ -42,6 +42,11 @@ end # ? second @reexport module ConfirmNotebook include("./Confirm.jl") end # 0 second + +@reexport module ReadingTimeNotebook + include("./ReadingTime.jl") +end # ? second + module CombineNotebook include("./Combine.jl") end # 0.06 second diff --git a/src/ReadingTime.jl b/src/ReadingTime.jl new file mode 100644 index 00000000..08314d3b --- /dev/null +++ b/src/ReadingTime.jl @@ -0,0 +1,922 @@ +### A Pluto.jl notebook ### +# v0.20.20 + +using Markdown +using InteractiveUtils + +# ╔═╡ 304b8b51-986a-4125-b3b1-acb38d3f90b5 +# ╠═╡ skip_as_script = true +#=╠═╡ +begin + import Pkg + Pkg.activate(Base.current_project(@__DIR__)) + Pkg.instantiate() + Text("Project env active") +end + ╠═╡ =# + +# ╔═╡ 97bd5888-08fe-4498-b48e-dd4db0a2f590 +begin + using HypertextLiteral + using Markdown +end + +# ╔═╡ b7afb360-f1ec-4eb4-8bd8-e82d71ad5171 +# Styles +const reading_time_css = @htl """ + +""" + +# ╔═╡ a2a3b8c6-2b45-4ab1-a631-1cb2cb9718b5 +const reading_time_js = (estimator) -> @htl(""" + + +""") + +# ╔═╡ 47803bec-eca2-4c76-b1d4-c8951ee4ccda +begin + local result = begin + + struct ReadingTimeEstimator + wpm::Int + position::Symbol + style::Symbol + + function ReadingTimeEstimator(; wpm::Int=200, position::Symbol=:top, style::Symbol=:minimal) + + allowed_positions = [:top, :floating] + + if position ∉ allowed_positions + throw(ArgumentError("Please select a position from the list of allowed positions :$allowed_positions. Got: `$position` + ")) + + end + + allowed_styles = [:minimal, :detailed] + if style ∉ allowed_styles + throw(ArgumentError("Please select a style from the list of allowed positions :$allowed_styles. Got: `$style`")) + end + + new(wpm, position, style) + end + end + + @doc """ + Add a reading time estimate to your Pluto notebook based on markdown content. + + # Arguments + - `wpm::Int=200`: Words per minute reading speed (typical range: 150-300) + - `position::Symbol=:top`: Where to display (`:top` or `:floating`) + - `style::Symbol=:minimal`: Display style (`:minimal` or `:detailed`) + + # Examples + ```julia + reading_time() # Simple "📖 5 min read" + + reading_time(wpm=250, style=:detailed) # "📖 Reading time: 4 minutes (850 words at 250 wpm)" + + reading_time(position=:floating) # Floating in corner + ``` + """ + ReadingTimeEstimator + end + + function Base.show(io::IO, m::MIME"text/html", estimator::ReadingTimeEstimator) + Base.show(io, m, @htl("$(reading_time_js(estimator))$(reading_time_css)")) + end + + result +end + +# ╔═╡ 7ecea127-265b-4eac-8fa0-e25e344d7e2b +ReadingTimeEstimator() + +# ╔═╡ 89131e87-bd73-4cfa-a93c-2d45a46cd389 +md""" +Nam vitae augue viverra, ullamcorper purus quis, egestas eros. Mauris congue ultrices interdum. Proin ut dictum odio, a blandit mi. Nullam porttitor odio eget mi porttitor dapibus. Ut in lacus nec eros tristique pellentesque. Curabitur quis quam sagittis quam tempus interdum et ut eros. Fusce non suscipit dui. Duis blandit turpis est, sit amet dictum quam luctus et. Praesent tempor, ex quis blandit consectetur, nisl nisl tincidunt lorem, ac molestie dolor nisi eget diam. Sed mollis, ligula id gravida gravida, sapien ante gravida quam, eu fermentum leo velit et magna. Mauris rutrum molestie sem sit amet finibus. +""" + +# ╔═╡ 1873d61f-a021-4919-9542-d91e019f9b59 +export ReadingTimeEstimator + +# ╔═╡ Cell order: +# ╠═304b8b51-986a-4125-b3b1-acb38d3f90b5 +# ╠═97bd5888-08fe-4498-b48e-dd4db0a2f590 +# ╠═47803bec-eca2-4c76-b1d4-c8951ee4ccda +# ╠═b7afb360-f1ec-4eb4-8bd8-e82d71ad5171 +# ╠═a2a3b8c6-2b45-4ab1-a631-1cb2cb9718b5 +# ╠═7ecea127-265b-4eac-8fa0-e25e344d7e2b +# ╠═89131e87-bd73-4cfa-a93c-2d45a46cd389 +# ╠═1873d61f-a021-4919-9542-d91e019f9b59 diff --git a/test/runtests.jl b/test/runtests.jl index c2faf845..28e01973 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -527,4 +527,6 @@ transform(el, x) = AbstractPlutoDingetjes.Bonds.transform_value(el, x) NotebookCard("https://plutojl.org/en/docs/ExpressionExplorer/index.html"; link_text="asdfasdf" ) |> hr NotebookCard("https://featured.plutojl.org/basic/basic%20mathematics"; link_text="Yes I want pizzaaa") |> hr + ReadingTimeEstimator() |> hr + ReadingTimeEstimator(wpm=2, position=:floating, style=:detailed) |> hr end