Can I use external themes with MkDocs on readthedocs.org? - read-the-docs

I switched from the included ReadtheDocs theme to the bootswatch United theme for my project. I did a pip install mkdocs-bootswatch for this theme, and changed theme: readthedocs to theme: united in my mkdocs.yml file.
However, although the project builds successfully in Read the Docs, the documentation retains the standard readthedocs theme. When I run it locally (using mkdocs serve), it appears correctly with the United theme.
Is there another line of code I should be tweaking somewhere? A requirements file I should add? How can I get the external theme to properly appear in the ReadtheDocs... or indeed, can I even use external themes on readthedocs.org?
Note: I did ask the MkDocs folks and they said it was a ReadTheDocs limitation, so if there is anything to be done, it seems like it will be a ReadTheDocs-related solution. Otherwise, I may have to switch to GitHub pages or something similar.

I took a look at ReadtheDocs source code and it appears that they actually override your settings config and force their own template. As I understand it, they do this because they inject JavaScript and navigation stuff specific to ReadtheDocs into your pages and by using a known theme, they can be sure the injections are done correctly. That said, there shouldn't be any technical reason why you can't use the same HTML as the readthedocs theme but perhaps different CSS to alter the look/styling of the pages. Its just that ReadtheDocs appears to not explicitly support this.
That said, I did notice that the template override only happens if 'theme_dir' not in user_config and self.use_theme. That gives you two possible paths to avoid the override. Just be aware that there will be no guarantee that the injected stuff will work correctly so tread carefully.
theme_dir is a Mkdocs setting. Rather than installing a MkDocs theme as a separate Python library, you could copy the theme files into a directory next to the docs_dir and then point the theme_dir setting to it. Just be sure to set theme: null so that MkDocs only uses the theme_dir.
Perhaps as a less aggressive approach, you could set theme: readthedocs, and then use theme_dir to only supply your own CSS files which would override/replace the CSS supplied by the built-in readthedocs theme. This should be less hostile to ReadtheDocs injections and give you a look you like. However, this may require more work to get right as you are restricted to the HTML of the existing theme and will need to author your own CSS (no using an already built theme).
For that matter, you could set theme to whatever theme you want and then point theme_dir to an empty directory. It would appear that ReadtheDocs only checks that theme_dir is set, and doesn't care what actually exists in the directory.
Note: I have not tested any of these suggestions and cannot be certain they will work. YMMV.
As an aside, the MkdDocs documentation about how this all works (interaction between the theme and theme_dir settings) is severely lacking right now. However some recent additions will become live when the next version of MkDocs (0.16) is released.
use_theme appears to be specific to readthedocs and hardcoded internally. My guess is that this will not be overridable by a user. A deeper investigation of the code would be needed to determine what, if any, options this provides.

Related

Theme-Chooser in Github - to choose a jekyll-theme vanished

I am currently setting up a page and I wonder where the GitHub theme-chooser has gone. According to the following instruction, I want to go through the process:
It seems that the theme-chooser has been removed. I want to use the jekyll-theme minimal (like caroly stransky does).
Is this documentation still correct and is the information still relevant?
update: see here the image of how it looks here
i want to add the line that carol did in the configuration; Christian it would be awesome if you can help here...
second update: hi there - since i cannot see the config.yml i think that i have to add the additional line to the so called raw file: see below the image
can you confirm that is that all right!?
love to hear from you
update3: well i guess that i ll need to create a new file named "_config.yml" and with this i ll ned to set it's contents to this: ´theme: jekyll-theme-minimal`´ I guess that i have to do this
update4: well i ve created the file - and i guess this is done right - but wait. I have to edit this file correctly
theme: jekyll-theme-minimal
Well i need to add this correctly - not as comment but as content of the file... This is pretty important.
The blog post (workwithcarolyn.com/blog/digital-cv-guide) is from 2020. The displayed images are outdated. In a test repo I couldn't find the option to select a theme anymore. The new pages setup page (https://github.com/YOURUSER/REPOSITORY/settings/pages) just contains a link to the docs:
The link to the docs explains how to set a theme for your site. Under point 5 the page says:
Add a new line to the file for the theme name.
To use a supported theme, type theme: THEME-NAME, replacing THEME-NAME with the name of the theme as shown in the README of the theme's repository. For a list of supported themes, see "Supported themes" on the GitHub Pages site.
The supported themes page is linking to the repository of each theme.
Some other themes are remote themes, e.g. Minimal. The repository explains how to add the theme:
To use the Minimal theme:
Add the following to your site's _config.yml:
remote_theme: pages-themes/minimal#v0.2.0
plugins:
- jekyll-remote-theme
You can have a look at https://github.com/cadamini/test/blob/main/_config.yml and the resulting page at https://cadamini.github.io/test/

Github dosen't recongize the other languages used in my repo

A while back, i made my very first Github repo. Since i added the documentation using HTML and CSS, github doesn't recongize it in the "Languages" bar. It only shows 100% Python.
How can i change it so it also includes HTML and CSS???
The "Languages bar" as you called it is powered by Linugist. According to their Documentation, Linguist ignores (or tries to ignore) generated files, binary data, documenatation and similar files.
Github's Linguist probably "ignores" your documentation folder which contains html and css or just understands that the most important code is Python.
Anyway, you can edit .gitattributes to show exactly what you want.
More info here https://dev.to/katkelly/changing-your-repo-s-language-in-github-5gjo

Is it possible to add a single custom HTML page to an existing Hugo theme like Academic?

What do you want exactly?
I have a website in Hugo. However I have a peculiar situation.
Scientists and Electrical Engineers and others may have specific needs. For Eg: Having a single page that shows a simulation. Or in my case using webbluetooth and webusb that I have written from scratch in HTML, CSS and JS. Moreover these pages may be generated by custom scripts. So you can have git submodules inside your hugo site that specifically cater to generating these custom, single page html that you just want to add to your website.
So all I want is to have a menu item or sidebar whatever the existing theme supports, but instead of showing the default html, it should show my custom, hard-coded, already ready and prepared html file - which may as well be an index.html file in a folder with all the necessary contents ready and cooked - something like the _site folder that jekyll creates.
What do you mean by custom html?
I mean it doesn't take the formatting of the hugo theme. It has its own formatting, but because its just a single page in the whole website its not fruitful to have its own layout written in Hugo or maybe its just worth the effort to do that cause you already have it working using some other technology.
What have you done so far and what works?
I am actually coming from a Jekyll background where it's as simple as changing the layout frontmatter and making it nil or even something that doesn't exist at all and jekyll does a great job of showing custom HTML in an existing theme. Tried the same with Hugo but that didn't work.
What are you testing on?
hugo-coder and(or) hugo-academic
Any specific requests?
Ideally I would like to have submodules in my hugo site folder where those submodules generate custom html in known folders and then somehow make a corresponding markdown file in Hugo that is responsible for showing the custom html.
I want to avoid writing the whole html in the markdown itself. But if no other solution is possible then I guess I don't have a choice.
Do let me know if its possible and worthwhile to pursue this and any references that might help.
So I don't know if this is the perfect solution but it somehow works for the moment. I will not accept it as its not perfect and I am waiting for some of the more experienced folks to answer.
I got something working by doing the following -
I had a page built using Jekyll. Jekyll builds the site in a folder called _site.
I copied the _site folder into static folder of Hugo and renamed it correspondingly to CustomHTML OR you could use the flag -d <destination folder> or declare it in the _config.yml file : destination: <destination folder>
Since I am testing it on hugo-acdemic theme, for that I added the following to the config.toml file to show it in the menu -
[[menu.main]]
name = "CustomHTML"
url = "CustomHTML/index.html"
weight = 50
hugo serve And it worked.
Cool thing is that I didn't have to bother about CSS and anything else. Hugo rendered the index.html in _site properly.
EDIT
Looks like the Hugo folks also suggest doing the same way.

Angular template theming

Within our application we're trying to achieve (html)templating based on themes. For example, if the specified theme is default, we should use the basic templates, but if the theme is 'coolTheme', all templates postfixed with '-coolTheme.html' should be used instead.
We have considered different solutions, but figured there must be a simple/default way to do this. These are the options we came up with:
Gulp task that puts all html files per theme in a {myTheme}-templates.js. When changing the theme angular resets the $templateCache, loads in the theme file and puts the templates in the $templateCache.
Gulp task that copies over all *-.myTheme.html to where the default templates should be (based on given theme parameter). Disadvantages are that you cannot change the theme on the fly.
Intercepting/decorating the $templateRequest, to check in a list/configuration file if the requested file is marked as 'themed', and then change the request to 'theFile-{myTheme}.html' instead
Which is the best way to handle this? And why? Does anyone have the 'perfect' solution for this?

Relative path to a stylesheet in Visual studio not working in preview

I'm assuming this is an easy question, but I'll be darned if I can find the answer.
I have a website in Visual Studio 2008. The paths to the stylesheets (and images) are in the following format /css/stylesheetname.css
At the root of the web project in Visual studio the folder exists as does the stylesheet. These paths work fine when running it in IIS.
If I use the inbuilt webserver in Visual Studio the paths fail because it puts the projectname in the path i.e. http://localhost:2020/projectname/default.aspx
In this case the / takes the path right back to http://localhost:2020
This is further compounded by the fact that if you click "design" the styles that import background images all fail although the stylesheet is imported correctly (becuase all other aspects of the stylesheet work i.e. .class{font-family:arial;} works but .class{background: url(/images/image.jpg)} does not).
I guess it's all to do with how Visual studio calculates its root path for the website, however I can't find a setting to change this.
Any ideas??
Update: as per Egil Hansen's answer I converted the paths in the CSS file to relative paths. However the background images still do not display in Design mode. I'll take a look at using Themes to get round this in due course.
I think the correct solution is to use relative urls in the style sheet instead of absolute urls as you use now.
Do note that relative urls in style sheets are relative to the location of the style sheet, not the current page being view by the browser.
If you use ASP.NET Themes, you can put all your website graphics in a /App_Themes/YourTheme/Images/ folder, and put your style sheet in the /App_Themes/YourTheme/ folder.
In your style sheet, you can then simply reference an image with url(Images/img.gif), and it will work both online and in development.
The you just need to assign your ASP.NET Theme to the page(s) you want, either through web.config's Pages section (<pages styleSheetTheme="Default">) that will assign a theme to all pages on the website or through the <%# Page ... directive on each page.
In general, you can do some really neat things with ASP.NET Themes and Skins, just take a look at the ASP.NET Themes and Skins Overview over at msdn.microsoft.com.
There are a few issues to be aware of with Themes in ASP.NET, take a look at my post How to take control of style sheets in ASP.NET Themes with the StylePlaceHolder and Style control, which explains and solves the issues I have come across so far.
I have been running projects using the custom Image folder for all my graphics for ASP.Net applications. While there have been advancement in this regard with the App_Theme and App_Code folder(s) available in the progressive VS IDE; I still kept my folder and it has not disapponited when deploying it on the server.
So with that said - the proverbial folder will be sitting with all the bin, App_Code and _Themes and the reference to it is made through this way
background: url(../image/..);
of course the code above sitting in the CSS file. It works for me all the time
not sure if this works for VS 2008 or not, but im using visual web developer 2010 and it worked for me:
1) click on the project in the solution explorer
2) it shows a "Virtual Path" property which is defaulted to "/projectname"
3) change it to "/" instead and it seems to do what is desired
let me know if this works for you!
it has been ages since I did anything in css, but maybe url(./images/image.jpg)
will work?
Edit:
Or rather ~/format /css/stylesheetname.css or ./format /css/stylesheetname.css as the url to the stylesheet.
I had the same issue and it drove me crazy. Solution is to add an Apps_Theme folder and copy the images into there. When you publish the site the folder structure is preserved and the imnges display.
I had set path css url image by
code { background:url(/images/xxx.jpg) no-repeat; }
and running file at IIS, so must to point default website to your project
how to running testing preview
type:
http://localhost/default.aspx
this is correct path same running on server
include file js or css can use "/" root path
cheers
Noboyband