docfx icon indicating copy to clipboard operation
docfx copied to clipboard

Url prettifier

Open AndreyAkinshin opened this issue 6 years ago • 12 comments

Right now, markdown files (articles) are translated to html files which are available via direct link like https://mydomain.com/articles/article-name.html. I want to "prettify" it and get an url like https://mydomain.com/articles/article-name/. Actually, I want a copy of article-name.html in https://mydomain.com/articles/article-name/index.html. Does DocFX provide any API for that?

AndreyAkinshin avatar Jun 08 '18 10:06 AndreyAkinshin

Not supported for now, but it will be supported in vNext.

superyyrrzz avatar Jun 12 '18 09:06 superyyrrzz

@superyyrrzz great! Any ETA when it will be available?

AndreyAkinshin avatar Jun 12 '18 10:06 AndreyAkinshin

We don't have an exact release date yet, it is a work on progress.

yufeih avatar Jun 13 '18 03:06 yufeih

This is implemented in v3.

We use pretty url by default: http://a.com/article-name/. It can be into http://a.com/article-name.html by setting uglifyUrl: true

yufeih avatar Sep 12 '18 11:09 yufeih

@yufeih, awesome, thanks! By the way, it will be possible to automatically generate redirects from ugly urls to pretty urls? (e.g., http://a.com/article-name.html -> http://a.com/article-name/). With such redirects, all external links to old urls will be valid after prettification.

AndreyAkinshin avatar Sep 12 '18 12:09 AndreyAkinshin

This is a static switch. docfx has no idea when you made the switch. It'll generate redirects for every new file.

Automatic redirect generation is best handled by other tools that know the exact files to be redirected during a change.

yufeih avatar Sep 13 '18 01:09 yufeih

Today, there's still no v3 released. So, this is a small quick and dirty workarround:

$destinationRoot = "path/to/output"

[RegEx]$Search = '(index\.html)"'
$Replace = '"'

[RegEx]$Search2 = '(\.html)"'
$Replace2 = '"'

ForEach ($File in (Get-ChildItem -Path $destinationRoot -Recurse -File)) {
    (Get-Content $File.FullName) -Replace $Search,$Replace -Replace $Search2,$Replace2 | 
        Set-Content $File.FullName
}

Live sample: https://www.aximo.games (hostet on github pages)

arakis avatar May 22 '20 19:05 arakis

@yufeih is it possible to backport this feature to v2?

AndreyAkinshin avatar May 31 '23 19:05 AndreyAkinshin

Reopen as the feature isn't available in v2.

yufeih avatar Jun 01 '23 03:06 yufeih

@yufeih any ETA when this feature will be available? Really looking forward to it! Thanks! 😊

mjegob avatar Nov 07 '23 14:11 mjegob

@mjegob A fixed is released in v2.73.2 to allow TOC expansion work on URL rewrite. Full URL prettifier however isn't supported yet.

yufeih avatar Nov 14 '23 08:11 yufeih