Hugo. Is there a way to generate a valid URL from asciidoc link:file.adoc[title] - hugo

I have a hugo project structure like this:
content/
_index.md
a.adoc
b.adoc
There is a cross-reference to the a.doc in b.adoc
link:a.adoc[The page "a"]
Hugo renders the link to the URL like this: http://my-site.com/a.doc
But this page doesn't exist and i get 404 when going to the URL.
The valid URL is http://my-site.com/a
Is there a way for generating a valid URL like above?
There may be a solution similar to markdown-render-hooks?
layout
_default
_markup
render-link.html

Related

How create a link from a parameter in React component?

In a React.js I have a variable that contains a url.
let linkab = 'www.example.com/about';
<Router><Link to={linkab}>About</Link></Router>
but this code adds localhost to the address on the link like this:
http://localhost:1985/www.example.com/about
how can I get the real link without localhost in the beginning?
Actually we use Link when we want to navigate to a different route in the same application.
But since you need want to navigate the user outside of your application anchor tag would be the best suitable one
<a href={linkab}>About</a>
Also, if you the provided url is not having any http or https protocol then by default it'll be considered as relative path. Hence, the provided url will be appended to the current browser address/url. So, in your case if you provide something like below then it will redirect to that url on click.
let linkab = 'http://www.example.com/about';
or
let linkab = 'https://www.example.com/about';
Just use regular <a target="_blank" href={linkab}>To external site</a> tag, no need to use Link. And add https:// before url.

Access url with params that is directly pasted in search bar in next js

So i know how dynamic routing and stuff works when you are navigating from inside the next.js app using or Router.push(). What I don't understand is say i have a URL:
http://localhost:3000/jhondoe
Now i directly paste this URL into the browser. How will next know which page to render? Keep in mind that the Jhondoe part is not exactly a page but a path param that i need to access to display stuff related to Jhon doe.
In next you can do something like [id] that is create a folder like this in pages and put your actual page here.

Change href of Live Status link in Wagtail Admin

I made a one page scrolling site using wagtail. I have a homepage model and everything else is child pages such as about us, events, etc. On the admin page it creates a slug with the title of the child page which is what the live status link uses. For example it is <a href="/about-us/">. Is there a way to change the live status link at all?
The page URL is constructed by calling the get_url_parts method on the page model - by overriding this method, you can customise the resulting URL:
http://docs.wagtail.io/en/v1.13.1/reference/pages/model_reference.html#wagtail.wagtailcore.models.Page.get_url_parts
http://docs.wagtail.io/en/v1.13.1/topics/pages.html#customising-url-patterns-for-a-page-model
Normally, if you're overriding get_url_parts, you'd want to make a corresponding customisation to your site's URL routing behaviour, to ensure that the page is actually available at the URL in question; this can be done with RoutablePageMixin. In this case, though, it sounds like you're just using these subpages as placeholders for page content, and aren't bothered about them being accessible at their own URL - so you can get away with simply returning '/' as the page path:
class MyChildPage(Page):
# ...
def get_url_parts(self, *args, **kwargs):
url_parts = super(MyChildPage, self).get_url_parts(*args, **kwargs)
if url_parts is None:
# in this case, the page doesn't have a well-defined URL in the first place -
# for example, it's been created at the top level of the page tree
# and hasn't been associated with a site record
return None
site_id, root_url, page_path = url_parts
# return '/' in place of the real page path
return (site_id, root_url, '/')
I ran into this question when using Wagtail as a headless CMS for a Gatsby site. As I do use the URLs generated by Wagtail to structure the Gatsby site, redefining the get_url_parts method does not help me. I do want to keep the page URL as is and use a different host when clicking on the "View Live" or "Live" button in the admin.
I found that overriding the serve() method of the pages that you want to be served by a different host allows you to do just that.
from django.shortcuts import redirect
class BlogPage(Page):
...
def serve(self, request):
site_id, site_root, relative_page_url = self.get_url_parts(request)
return redirect('http://localhost:8001' + relative_page_url)
In the code above, the serve method of the BlogPage model is overridden to use the request and the get_url_parts method to extract the requested relative_page_url (that is relative to the site root -- in development that would be http://localhost). Since my frontend keeps the same URL structure as the Wagtail site, I just use the extracted relative_page_url and combine it with the host of the frontend (in this development case localhost:8001) and return a redirect response (generated with django.shortcuts.redirect) to that full URL.
It probably makes sense to turn this override into a mixin and a setting, so it does not have to be defined on every page model and the redirect host can be differentiated between environments.
You could also use the same logic of overriding the serve() method to redirect to any other location you may choose.

How can I have multiple states pointed to the same file?

I have a basic 404 page that I want to display if someone types in a bad url. Our application is broken up into multiple modules, which I'll call Module1 and Module2 for this question.
I'm defining the 404 route in both Module1 and Module2 like this:
state("404", {
url: "/404",
templateUrl: "page-not-found/page-not-found.html"
})
$urlRouterProvider.otherwise("/404");
In Module1, all of the routes look like this: /home, /something, /somethingelse
In Module2, all of the routes look like this: /module2/home, /module2/something, /module2/somethingelse
All of those routes have different templateUrl paths.
When I type /badroute, everything works fine. I get the 404 page and there is much rejoicing (yaaaaaaay). However, when I type /module2/badroute, I don't get to the page and instead get a generic Angular error. Even if I changed the names and/or url's of the states, the same thing issue occurred because they were pointing to the same file.
When I set the 404 templateUrl to a different file path for Module2, everything worked as I expected; both /asdf and /module2/asdf took me to their respective 404 pages. As I don't want to create several 404 error pages, how can I have routes in different modules point to the same html file without it blowing up in my face? There is no parent-child relationship among the modules; they're all different chunks of the application.

How to serve a file if URL doesn't match to any pattern in Go?

I'm building a Single Page Application using Angular 2 and Go, and in Angular I use routing. If I open the site at, say, http://example.com/, Go will serve me my index.html file, which is good because I wrote this:
mux.Handle("/", http.FileServer(http.Dir(mysiteRoot)))
Now I have a route in Angular, let's say, /posts, and If it's a default route (that is, when useAsDefault is true) or if I just manually go to http://example.com/posts, I'll get a 404 error from Go, which means that no handler is specified for this path.
I don't think that creating a handler in Go for every single Angular route is a good idea, because there may be a lot of routes. So my question is, how can I serve index.html in Go if the request URL doesn't match any other pattern that I set in my ServeMux?
Well, that was pretty easy actually.
The net/http documentation says this:
Note that since a pattern ending in a slash names a rooted subtree,
the pattern "/" matches all paths not matched by other registered
patterns, not just the URL with Path == "/".
So I needed to do something with my "/" handler. http.FileServer looks for files in a directory that is specified in the pattern string, so I just replaced it with this:
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, mysiteRoot + "index.html")
})
And it works just fine.
I think you will need to change the URL provider settings in your angular2 app to use HashLocationStrategy. Using this, your routes will be of the form
#/posts
and will not trigger any route in your golang app.

Resources