Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2023-01-07 00:44:55 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2023-03-07 18:09:23 +0300
commit447a990e829be758ce7e11e2d78e521395138649 (patch)
tree71ad7b66f09246daeba0b82150f05008d021e60a
parent7846dd526e31550f845e8e66452d11be822c8689 (diff)
Set a description if not set in the front matter
1. Remove the H1 title 2. Choose the first 15 words 3. Replace any Markdown links with the content inside brackets ([]) 4. Add three dots at the end
-rw-r--r--Rules9
-rw-r--r--layouts/head.html6
2 files changed, 10 insertions, 5 deletions
diff --git a/Rules b/Rules
index 08ff670a..e41b9220 100644
--- a/Rules
+++ b/Rules
@@ -2,6 +2,7 @@
# vi: set ft=ruby :
TITLE_FILTER_REGEXP = /(#\s|#{BadgesFilter::BADGES_MARKDOWN_PATTERN})/.freeze
+MARKDOWN_LINK_REGEXP = /\[(.*)\]\(.*\)/.freeze
preprocess do
badges_filter = BadgesFilter.new
@@ -40,6 +41,14 @@ preprocess do
# Run badges filter with title fragment
item[:title_badge] = badges_filter.run_from_markdown(raw_title.match(BadgesFilter::BADGES_MARKDOWN_PATTERN).to_s)
+
+ # Set a description if not set in the front matter
+ # 1. Remove the H1 title
+ # 2. Choose the first 15 words
+ # 3. Replace any Markdown links with the content inside brackets ([])
+ # 4. Add three dots at the end
+ item[:description] ||= item.raw_content.gsub(raw_title, '').split[0..15].join(' ').gsub(MARKDOWN_LINK_REGEXP, '\1').to_s.insert(-1, '...')
+
end
if item.identifier.match?('/ee/architecture/**/*.md')
diff --git a/layouts/head.html b/layouts/head.html
index 99284d35..ec7c3907 100644
--- a/layouts/head.html
+++ b/layouts/head.html
@@ -6,11 +6,7 @@
<title><%= @item.key?(:title) ? "#{item[:title]} | GitLab" : "GitLab Documentation" %></title>
<meta property="og:title" content='<%= @item.key?(:title) ? "#{item[:title]} | GitLab" : "GitLab Documentation" %>'>
<% end %>
-<% if @item[:description] %>
- <meta name="description" property="og:description" content="<%= @item[:description] %>">
-<% else %>
- <meta name="description" property="og:description" content="Documentation for GitLab Community Edition, GitLab Enterprise Edition, Omnibus GitLab, and GitLab Runner.">
-<% end %>
+<meta name="description" property="og:description" content="<%= @item[:description] %>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<% if @item[:noindex] or !production_and_default_branch? %>
<meta name="robots" content="noindex, nofollow">