Replies: 2 comments 1 reply
-
Hello @v20100v thanks for the suggestion and all the hard work. Let me know your thoughts and what you think about my comment on the width change specifically. I think there is something awesome here and I am happy to open a branch to collab with you on it. p.s. sorry if the reply took some time have been busy |
Beta Was this translation helpful? Give feedback.
-
It would actually be nice to be able to be able to specify the default value of the zen mode (enabled or disabled by default) |
Beta Was this translation helpful? Give feedback.
-
First, I wanted to thank you for your work in Blowfish. Thx!!!
Zen-mode = occupy full width available in browser
The idea is to enhance the reading experience in Blowfish theme, by optimizing the article text to occupy the full width available in the browser. Users have the option to activate this feature at their convenience through a straightforward button located in the article header.
To enable or disable Zen mode, image an implementation of a straightforward button. This button will be easily accessible in the header of the article, providing users with a seamless way to toggle this immersive reading experience on or off. Crucially, the implementation will ensure that user preferences persist as they navigate through different pages. This means if a user activates Zen mode on one page, it remains active when moving to another, creating a consistent and personalized reading experience.
So what do we want to do :
A picture more than words
before-after-zen-mode.mp4
Implementation proposal
I did not create a fork to offer you this functionality... waiting for your opinion. But I have already coded it for my use (by override) which I share with you below.
Create a zen-mode button (partial layout)
Begin by establishing a dedicated space for the zen-mode button. In the
./layouts/partials/meta/
local folder, create a new file named zen-mode.html. This file will serve as the container for the zen-mode button’s layout and functionality.Inside this newly created file, we define the structure of the button, and we load appropriate javascript with this instruction {{ $jsCode := resources.Get "js/zen-mode.js" }}. Notes that we added data-attributes (data-title-i18n-disable and data-title-i18n-enable) to store the button titles, depending on its state (activated or deactivated), in order to benefit of multi-languages support.
Put this zen-mode button into the article layout
This button will be placed at the head of each article, providing users with an easily accessible control for toggling Zen mode. To do it, we override the partials layout used for article in the Blowfish theme. Specifically, we override the file article-meta/basic.html, by creating the new file ./layouts/partials/article-meta/basic.html.
This button is added only if the showZenMode option is activated in the Hugo configuration, specifically within the configuration file located at ./config/_default/params.toml. The conditional check ensures that the Zen-mode button template is included only when the showZenMode option is set to true in the Hugo configuration. Don’t forget to activate it.
Update "single" layout
Add a new div with
.zen-mode
class into this layout.Addding customs icons
Placing these below SVG icon, edit.svg and expand.svg, into the dedicated ./assets/icons folder.
edit.svg : This edit icon bellow override the one used in the base theme.
expand.svg : A new addition
Adding CSS styles
Put this CSS style into the folder ./assets/css/custom.css.
The CSS class
.zen-mode-enable
ensures article occupy the full viewport width, have a maximum width of 1600px, and include padding for readability.Adding internationalization (i18n)
In the Blowfish theme, default translations can be overridden by creating a custom file in the ./i18n/ directory. So, to customize title attributes for the Zen-mode button, create a custom language definition file for each language you want to support.
Example languages definitions for zen-mode button
By storing i18n texts in data attributes within the HTML, you ensure dynamic content updates based on the user’s language preference. JavaScript is utilized to fetch these i18n values dynamically, allowing for real-time updates to the Zen-mode button title attribute.
To handle i18n for the Zen-mode button title attribute, we store the texts in HTML data attributes within the partial layout.
Then these data attributes can be then fetched in JavaScript, like this.
Adding Javascript
Create the new JavaScript file zen-mode.js into ./assets/js/ folder. It will be responsible for managing the click event and defining the behavior of the Zen mode button.
Few remarks about its javascript :
The click event on the Zen-mode button is registered using the addEventListener. It waits for the DOM to be completely loaded, by utilizing the DOMContentLoaded event.
Local storage is employed to maintain user configuration across web navigation. The option blowfish-zen-mode-enabled is initially set to false, and it is updated each time the user clicks the button. Upon page load, the script checks if this option is set to true and, if so, calls the callback function _toogleZenMode to activate the Zen mode.
If you're interested, I can create a PR for this (less ugly than doing custom override)... if i found some time.
Cordialy,
2o1oo
Beta Was this translation helpful? Give feedback.
All reactions