diff options
author | parsiya@gmail.com <parsiya@gmail.com> | 2016-07-31 21:29:35 +0300 |
---|---|---|
committer | parsiya@gmail.com <parsiya@gmail.com> | 2016-07-31 21:29:35 +0300 |
commit | 4fd5a722b61adb765e38d03531c190f995af7a6d (patch) | |
tree | 226eabdae5b356af31e44a8e8c241e63a1f8e977 | |
parent | 7c88ff25fb4b45efec1918f79b2d961d0ed687b9 (diff) |
Add a global parameter to control if navigation links open in a new window. Fixes #13
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | layouts/partials/navigation.html | 4 | ||||
-rw-r--r-- | sample-config.toml | 4 |
3 files changed, 12 insertions, 3 deletions
@@ -173,7 +173,7 @@ For example, if your css files are `static/css/custom.css` and `static/css/custo ## <a name="menu"></a>Navigation menu Links to the left of the navigation menu (everything other than Google search and RSS icon) can be configured here. Navigation menu is generated using the `hugo-octopress/layouts/partials/navigation.html` template. -All links open in a new window except links to root. If the URL is "/" the link will not open in a new window (you can see this logic in the partial template). +By default navigation menu links will open in the same window. You can change this by setting the `navigationNewWindow` parameter in the config file as seen below. Links to root ("/") will always open in the same window. Currently Hugo does not support adding custom attributes to menu items. Links are sorted according to weight from left to right. For example a link with weight of `-10` will be to the left of links with weight `0` or `10`. Links can be added to the `config.toml` as follows: @@ -191,6 +191,11 @@ Links are sorted according to weight from left to right. For example a link with Name = "This theme - add link" URL = "https://www.github.com" + [params] + # if set to true, navigation menu links will open in a new window with the exception of links to root ("\") + # if this item does not exist or set to false, then navigation menu links will open in the same window + navigationNewWindow = true + The search engine can also be customized in the `config.toml` file as follows: [params] diff --git a/layouts/partials/navigation.html b/layouts/partials/navigation.html index 2158654..82d3d62 100644 --- a/layouts/partials/navigation.html +++ b/layouts/partials/navigation.html @@ -1,12 +1,12 @@ <!-- reading menu items from config file --> <ul class="main-navigation"> - <!-- do not open links to root in new window - otherwise any other link can be opened in new window --> + <!-- links to root open in the same window - other links will be opened in a new window if navigationNewWindow is set to true in the config file --> {{ range .Site.Menus.main }} {{ if eq .URL "/" }} <li><a href="{{ .URL | absURL }}" title="{{ .Name }}">{{ .Name }}</a></li> {{ else }} - <li><a href="{{ .URL | absURL }}" target="_blank" title="{{ .Name }}">{{ .Name }}</a></li> + <li><a href="{{ .URL | absURL }}" {{ if eq $.Site.Params.navigationNewWindow true }} target="_blank" {{ end }} title="{{ .Name }}">{{ .Name }}</a></li> {{ end }} {{ end }} </ul> diff --git a/sample-config.toml b/sample-config.toml index d3c8f96..31a6c88 100644 --- a/sample-config.toml +++ b/sample-config.toml @@ -65,6 +65,10 @@ post = "/blog/:year-:month-:day-:title/" # change the post URL to look like the [params] + # if set to true, navigation menu links will open in a new window with the exception of links to root ("\") + # if this item does not exist or set to false, then navigation menu links will open in the same window + navigationNewWindow = true + # number of recent posts that will be shown in the sidebar - set to 0 or remove to hide this section sidebarRecentLimit = 10 |