Replies: 6 comments 1 reply
-
|
Addition : I mainly write JS / Node.js / CSS / frontend things for years, however not so familiar with python. |
Beta Was this translation helpful? Give feedback.
-
Some JS refactor advice:we can limit some JS functions only have effect on some limited pages, like using if(window.location.href.match(/RegExp/)){
let doSomethingFunction = () => {};
document.querySelector('.someClass').addEventListener('click', doSomethingFunction);
}we can also prevent global variable name pollution by wrap all JS codes to a function, like: we can also modify onload to a jquery (function(){
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function someOnLoadFunction(){
// move existing LoadPage() functions inside here
};
ready(someOnLoadFunction);
})();Also, we can use a CDN to distribute some big JS / CSS filesThere is no need to copy css / js from another repo to this repo. we can support configs in yaml, for different CDN providers, in future. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
The toc code has been added to the master branch 4db1b40 |
Beta Was this translation helpful? Give feedback.
-
|
I now notice that in your solution the toc remains available at the top. With my solution if you scroll down you lose the toc. You seem to know your way around the code pretty well. If you duplicate the template of the layout that you want, then you can change it to suit your own needs and use that to build your website. That will be a way more stable way to build on top of obsidianhtml, because the template/css is in constant flux. If you make your own template then you can do things like this: <body>
<div id="header"></div>
<div id="toc-container"></div>
<div id="content-container">{content}</div>
<script>
function populateToc(){
document.getElementById('toc-container').innerHtml = document.getElementById('toc').innerHtml
}
document.addEventListener('DOMContentLoaded', populateToc);
</body>Which will be way easier than trying to pry it out of the |
Beta Was this translation helpful? Give feedback.
-
|
we shouldn't trust DOMContentLoaded because this event only fire once and our js codes may execute after DOMContentLoaded event fired, that's why we should also check document.readyState the reason why ready and load have similar performance is those third party big JS / CSS dependencies blocks page render. more js codes and more controls like above is common for our projects becoming bigger and more complex, inject JS events inside HTML may not match our advanced requirements in the near future, and html injected JS functions name should exists on global window, that may pollute other vars and may have potential conflict issues . try to find a better way to arrange JS codes can also make we figure out which page area has which js functions executed easier. inject js to HTML are intuitively and suitable for now but lack advanced control and pollute global vars. |
Beta Was this translation helpful? Give feedback.




Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
my fork version implement TOC on mobile (only on documentation mode) after did tons of CSS / JS tricks, on end of April.
toc_on_mobile_demo.mp4
it modified one container's flex order and did some media queries, and modified some JS, and modified headings link anchor without
!(because I do not need tabs mode so I do not need those#!xxtricks).On this process, I found some
onload=func()onclick=func()inside HTML codes,maybe we can refactor those to JS codes by
document.querySelector(selector).addEventListener('load or click or others', afunc)also, CSS / CSS class names / CSS ids are hard to distinct which page /area uses which lines of CSS.
However my fork version became too far away from obsidian-html newest version.
My question are:
Is it possible to show TOC on mobile devices, for every modes?
Is there a better way to implement TOC for mobile on documentation mode?
Do you have any plan to refactor codes like JS event binding / CSS class names and ids , any plan to find a better way to arrage JS codes ?
thanks.
Beta Was this translation helpful? Give feedback.
All reactions