Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags including lang and hreflang attrs for all docs #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/gluegun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,34 @@ def self.copy_with_path(src, dst)
FileUtils.cp_r(src, dst)
end

def self.link_is_translated(slug)
if @site_map['Output'] === 'docs'
return is_link_valid("https://docs.min.io/cn/" + slug)
elsif @site_map['Output'] === 'cn'
# All Chinese docs have English translations, so we can return true
return true
else
return false
end
end

def self.is_link_valid(link)
begin
uri = URI.parse(link)
req = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
req.use_ssl = true
end
res = req.request_head(uri.path)
if res.code === "200"
return true
else
return false
end
rescue => e
return false
end
end

end
end
52 changes: 51 additions & 1 deletion lib/index.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!DOCTYPE html>
<html>
<%- if @site_map['Output'] === "docs" -%>
<html lang="en">
<%- elsif @site_map['Output'] === "cn" -%>
<html lang="zh">
<%- else -%>
<html>
<%- end -%>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Expand All @@ -17,6 +23,28 @@
<%- end -%>
<meta name="description" content="<%= key2["SEO Description"] %>">
<meta name="keywords" content="<%= key2["SEO Keywords"] %>">
<%-# generate link tags with hreflang attribute for all pages excluding index -%>
<%- if link_is_translated(key2['Slug']) -%>
<link
rel="alternate"
hreflang="en"
href="https://docs.min.io/docs/<%= key2['Slug'] %>"
title="lang"
>
<link
rel="alternate"
hreflang="zh"
href="https://docs.min.io/cn/<%= key2['Slug'] %>"
title="lang"
>
<%- elsif @site_map['Output'] === "docs" -%>
<link
rel="alternate"
hreflang="en"
href="https://docs.min.io/docs/<%= key2['Slug'] %>"
title="lang"
>
<%- end -%>
<%- else -%>
<%-# Take first entry specified under the 'Documents' key for index page-%>
<%- if !@site_map['Documents'][0].values[0][0]["SEO Title"] -%>
Expand All @@ -32,6 +60,28 @@
<%- @site_map['Documents'][0].values[0][0]["Slug"] = get_slug(@site_map['Documents'][0].values[0][0]) -%>
<%- end -%>
<link rel="canonical" href="/<%=@site_map['Output']%>/<%=@site_map['Documents'][0].values[0][0]["Slug"]%>.html" />
<%-# generate link tags with hreflang attribute for index page -%>
<%- if link_is_translated(@site_map['Documents'][0].values[0][0]["Slug"]) -%>
<link
rel="alternate"
hreflang="en"
href="https://docs.min.io/docs/<%= @site_map['Documents'][0].values[0][0]["Slug"] %>"
title="lang"
>
<link
rel="alternate"
hreflang="zh"
href="https://docs.min.io/cn/<%= @site_map['Documents'][0].values[0][0]["Slug"] %>"
title="lang"
>
<%- elsif @site_map['Output'] === "docs" -%>
<link
rel="alternate"
hreflang="en"
href="https://docs.min.io/docs/<%= @site_map['Documents'][0].values[0][0]["Slug"] %>"
title="lang"
>
<%- end -%>
<%- end -%>

<link href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" rel="stylesheet">
Expand Down