Jekyll gh-pages disappearing site url - hyperlink

I built a blog using jekyll and githubpages, and everything was going swimmingly until I added a custom domain name. After adding a custom domain name any link embedded in the website to another part of the blog (except for the homepage) is broken.
i.e. http://blog.com/about becomes -> http://about
i.e. http://blog.com/contact becomes -> http://contact
I can type in any of the addresses manually and it works fine, but if I click a link on the website to a post, the about page, or the contact page I get the broken url. How do I stop the site portion of the url from disappearing? Link to blog and its repository below
blog
repository

To generate the correct URL, you need to prepend the site.url variable.
You can generate the URLs manually in index.html:
{{site.url}}/{{ site.baseurl }}{{ post.url }}
Or use absolute_url to have them added automatically (it prepends site.url and site.baseurl):
{{ post.title }}

Related

IIS deployment Issue - my web app fails when clicking a function link. I get 'This localhost page can't be found'

I have on my development machine (Windows 10 Pro) and the IIS Web Server installed.
I used VS 2017 to develop a .NET web application. It works fine when it is run in VS. The menu links find their correct action methods. It performs as expected.
I have a problem in IIS whereby I have published the .NET (.NET framework 4.8) web application.
The publish to IIS created the folder on my C drive: inetpub\wwwroot\ProfileAndOrBlog.
I launch the web app in the browser with this URL: http://localhost/ProfileAndOrBlog.
I then sign into the web app using a top menu item just fine. That menu link is coded in the view as:
<li>#Html.ActionLink("Sign In", "SignIn", "SignIn", routeValues: null, htmlAttributes: new { id = "signinBtn", #class = "btn btn-primary my-signin-btn" })</li>
The URL generated is: http://localhost/ProfileAndOrBlog/SignIn/SignIn
After sign in, I get this page.
The URL generated is: http://localhost/ProfileAndOrBlog/User
I can now click on any side bar menu (a function of the app) - a link.
When I use the side bar menu link 'Make Suggestions' coded in the view as:
<i class="fa fa-edit fa-fw"></i> Make Suggestions
I get a 'This localhost page can't be found'.
The URL generated is: http://localhost/UserSuggestionMaint/Index.
It does not have the ProfileAndOrBlog/ as part of the route.
Note: if I manually add in the missing part of the route to the URL, it works.
http://localhost/ProfileAndOrBlog/UserSuggestionMaint/Index
So, why is that route part missing?
I don't quite get your question but it seems your problem is simply about routes.
When using links
<li>#Html.ActionLink("Sign In", "SignIn", "SignIn", routeValues: null, htmlAttributes: new { id = "signinBtn", #class = "btn btn-primary my-signin-btn" })</li>
Simply means it should display "Sign In" on a button and the link will be mapped to something like below:
"/SignIn/SignIn"
and
"/UserSuggestionMaint/Index"
In simple terms routes are usually "/Controller/action" in MVC.
So make sure you are referencing the right action method and it will work.
Using "/UserSuggestionMaint/Index" means the controller should be something like UserSuggestionMaintController and the Index action which will render the Index View.
Something you need to know about using absolute and relative paths in hyperlink <a href>,
Beginning with http:// or //. The browser will resolve the link as an
absolute URL.
Beginning with a single /. The browser will resolve the link as
relative to the domain.
Beginning with text. The browser will resolve the link as relative to
the page.
Beginning with #. The browser will look for an HTML element on the
same page (by ID) and scroll to it if found.
So when you use <a href="/UserSuggestionMaint/Index">, it adds this content after domian not current url.
But when you use #Html.ActionLink, it returns a specified link text according to an anchor element.
In my test, I use #Html.ActionLink in layout page. When I set the MVC application as a separate site, #Html.ActionLink generates a hyperlink likes this:
If I set the MVC applciation as a sub application under a site, it likes this:
Part of /ProfileAndOrBlog url is necessary so that IIS can know which application you want to access. Then asp.net route can know UserSuggestionMaint is controller and index is action.
The solution is:
Not use relative URL of hyperlink but absolute URL. <a href="http://domain name/ProfileAndOrBlog/UserSuggestionMaint/Index">.
Deploy the mvc application as a separate site not a sub application under default web site.
Not use but #Html.ActionLink to dynamically generate a hyperlink.
Thanks all for the insight.
To not change each of the href's to add in the tilde to the beginning of the path as suggested, I instead changed my Publish Profile. I had 'ProfileAndOrBlog' as part of the Site name (Default Web Site/ProfileAndOrBlog) and the Destination URL (http://localhost/ProfileAndOrBlog). I removed it in both places and it resolved the URL problem. Here is how my Publish Profile is now:
I now can successfully access all the functions of my web app when I launch the web site in the browser with this URL: http://localhost
So for my 'Make Suggestions' link, the URL is now: http://localhost/UserSuggestionMaint/Index.

IIS adds domain to website url

I have a ASP .NET MVC 5 project that is hosted with IIS7.
In a product page I have this code:
blabla
It is hosted on domainx or ipx. Now when I browse to the site and hover over the url there, it shows me it is headed to www.domainx.com/www.domain.com. If I use the IP it is the same thing, but instead it prefixes the url with the IP.
What is causing this and/or how can I stop it/ prevent it from happening?
I had reproduced your issue in a sample project using SO as anchor hyperlink on index page (Views/Home/Index.cshtml), changing http:// protocol to just www:
Stack Overflow
Surprisingly the URL generated on index page when hovering on the anchor link written as [IP address]/www.stackoverflow.com or [domain name]/www.stackoverflow.com.
However when http:// protocol added without using www prefix, the absolute path rendered to correct SO URL.
I concluded that instead of only using www prefix, specify http protocol on your absolute URL path:
blabla
or if you want to create your site root hyperlink use Html.ActionLink like this:
#Html.ActionLink("blabla", "Index", "Home")
or use plain anchor tag:
blabla
IMHO, Razor view engine may treat URL string inside href attribute of anchor tag(s) as controller name under site root IP/domain if the URL protocol is not specified, thus HTTP prefix is required to differentiate between controller name and external absolute URL path.
Any suggestions welcome.

Trouble with relative URLs in a master page logo between development and live

I have a master page which displays a footer with the company logo in it.
The URL is dynamic and pulled from the database as different companies have different logos when they log in.
The code is a simple view with <img src='#Model.TheUrl'> in.
The model is populated like:
model.TheUrl = "/Images/Logos/" + logoName;
The problem I have is that as you navigate around the site, the logo stops working, e.g. you're on www.site.com/home and you go to www.site.com/home/pages
I've tried all variations of / before and not before. I suspect the issue is that on my local machine, the URL of my website is localhost/MySiteName/ but on the staging server it's www.mydomain.com. I think this creates a problem. Maybe changing /Images/Logos... to /MySiteName/Images/Logos would work, but that wouldn't work when it was deployed.
How can I fix this?
You can use the UrlHelper to achieve this.
Change your model value to
model.TheUrl = "~/Images/Logos/" + logoName;
And then use the UrlHelper in the View:
<img src='#Url.Content(Model.TheUrl)'>
This will create a base-relative url.

How to retrieve web site favicons?

I am using Ruby on Rails v3.0.9 and I would like to retrieve the favicon.ico image of each web site for which I set a link.
That is, if in my application I set the http://www.facebook.com/ URL I would like to retrieve the Facebook' icon and use\insert that in my web pages. Of course I would like to do that also for all other web sites.
How can I retrieve favicon.ico icons from web sites in an "automatic" way (with "automatic" I mean to search for a favicon in a web site and get the link to it - I think no because not all web sites have a favicon named exactly 'favicon.ico'. I would like to recognize that in an "automatic" way)?
P.S.: What I would like to make is something like Facebook makes when to add a link\URL in your Facebook page: it recognizes the related web site logo and then appends that to the link\URL.
http://getfavicon.appspot.com/ works great for fetching favicons. Just give it the url for the site and you'll get the favicon back:
http://g.etfv.co/http://www.google.com
Recently I have written some similar solution.
If we want find favicon url, that can be not only .ico file and can be not in the root, we should parse target site html.
In Ruby on Rails, I have used nokogiri gem for html parsing.
First we parse all meta tags where itemprop attribute contains image keyword. It is necessary in situations where target site used https://schema.org/WebPage template, that more modern technology than just link tag.
If we found it, we can use content attribute as favicon url. But we should check it for really URL existence, just to be sure.
If we can't found some meta tags, then we search for standard link tags, where rel attribute contains icon keyword. This is W3C standard situation (https://www.w3.org/2005/10/howto-favicon)
And some code of my solution:
require 'open-uri'
def site_icon_link site
icon_link = nil
url = nil
doc = Nokogiri::HTML(open(site))
metas = doc.css("meta[itemprop*=image]")
if metas.any?
url = metas.first.attributes['content'].value
else
links = doc.css("link[rel*=icon]")
if links.any?
url = links.first.attributes['href'].value
end
end
if url =~ URI::regexp
icon_link = url
elsif (site + url) =~ URI::regexp
icon_link = site + url
end
icon_link
end
The favicons are being found by two ways. First, there is a 'hardcoded', traditional name of `http://example.com/favicon.ico'.
Second, the HTML pages may define the favicon in their <head> sections, by <link rel="icon"...> and a few other. (You may want to read the Wikipedia article about favicon)
So, your automat may fetch the main page of given website, parse it and check whether there are proper <link> tags, and then, as a fallback, try the "hardcoded" favicon.ico name.
I think I missed your question ...
you want to grab a favicon from another site and make it yours?
if that's what you want, you can get directly from the home icon and save it in your public folder.
thus: www.facebook.com favicon: www.facebook.com/favicon.ico
take that image and save with the name favicon in your public folder
done it should be sufficient
if you want it dinamicaly you can use jquery, but if you want that static you can put a image tag pointing to: [root url of the website]/favicon.ico
like this: <%= image_tag "#{website.url}/favicon.ico" %>
With javascript (jQuery), like this: http://jsfiddle.net/aX8T4/
Can't you just use a regular img tag with the src attribute pointing to the favicon?
<img src="http://www.facebook.com/favicon.icon">
This assumes a browser recognizes a .ico file as an image. Helped methods would probably work with this too.
You can do it easily with pismo gem.
Quick example to get the url of Facebook's favicon:
Pismo::Document.new('http://www.facebook.com/').favicon
Here's my ruby method, that will strip the end off a URL, append the favicon, and produce an image tag.
def favicon_for(url)
matches = url.match(/[^:\/]\/(.*)/)
image_tag url.sub(matches[1], '') + '/favicon.ico', {width: '16px', height: '16px'}
end

NerdDinner main logo link

I have uploaded the nerddinner sample to "www.example.com/test/nerd". When a mouse is on menu tab such as "Find a host" then the link is shown at the bottom of Internet explorer as "www.example.com/test/nerd/Dinner" with the contoller name "Dinner". When the mouse is on the main logo which is on top and left, the link shown as "www.example.com". So it direct me to "www.example.com" instead of "www.example.com/test/nerd"
Where can I change it? I have tried to change the "start url" from the application property, but it did not work.
The NerdDinner application links to the / path when you click on the logo. This points you to the domain root: example.com.
If you want the link to point to your home page instead, there are two ways of doing that:
Have the link point to ~ instead - that's the application root. If you configure the directory you installed NerdDinner in as an IIS application, the controller action with the "" route will handle the request.
Change the <a href="/" to point to your controller action by name: <a href="<%= Url.Action("Index","Home") %>"
Both ways work, but I recommend using the first one, because it will point to whatever action is routed to ""; in other words, if you change the name of your home page action, for example, the link will still work.
This application assumes that is installed in the root of the domain, and therefore just contains the path "/". You'll need to edit NerdDinner/Views/Shared/Site.Master. The line you need to touch is
<h1></h1>
Try changing this to
<h1></h1>
I don't have ASP.NET set up anywhere I can try this, so it probably won't work as is. Hopefully that will at least get you started if it doesn't work perfectly.

Resources