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:
authorEvan Read <eread@gitlab.com>2023-04-24 01:36:35 +0300
committerEvan Read <eread@gitlab.com>2023-04-24 02:42:38 +0300
commit0b8149316bd2cd775ae0d525e886f89056ac24b5 (patch)
tree974c70c2186b48e96e74da091b0b0b2effa62f37
parent3593498588cdd3c02811a5e662054630f37ff369 (diff)
Add link statistics report to project
-rw-r--r--.gitignore1
-rw-r--r--.gitlab/ci/test.gitlab-ci.yml16
-rw-r--r--.rubocop.yml2
-rw-r--r--Makefile8
-rw-r--r--doc/testing.md14
-rw-r--r--lib/checks/link_stats.rb32
-rw-r--r--lib/gitlab/docs/link.rb37
7 files changed, 110 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index df16e7c9..e0403e79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ tmp/
vendor/
node_modules/
coverage/
+link_stats.txt
diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml
index 6dc4a6f0..82e1f80f 100644
--- a/.gitlab/ci/test.gitlab-ci.yml
+++ b/.gitlab/ci/test.gitlab-ci.yml
@@ -186,6 +186,22 @@ test_external_links:
- bundle exec nanoc check external_links
#
+# Run link statistics report
+#
+link_statistics_report:
+ extends:
+ - .bundle
+ - .rules_chores
+ stage: test
+ script:
+ - bundle exec nanoc check link_stats > link_stats.txt
+ artifacts:
+ name: "link statistics report"
+ paths:
+ - link_stats.txt
+ expire_in: "1 day"
+
+#
# Run markdownlint to find EOL whitespace to clean up
#
test_EOL_whitespace:
diff --git a/.rubocop.yml b/.rubocop.yml
index 371edfd4..809c0fca 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -18,6 +18,8 @@ Naming/FileName:
# Project is not a Rails project
Rails/NegateInclude:
Enabled: false
+Rails/Output:
+ Enabled: false
Rails/RakeEnvironment:
Enabled: false
diff --git a/Makefile b/Makefile
index e445dc17..127c7f73 100644
--- a/Makefile
+++ b/Makefile
@@ -109,6 +109,10 @@ clean:
@printf "\n$(INFO)INFO: Removing tmp and public directories...$(END)\n"
@rm -rf tmp public
+clean-link-stats:
+ @printf "\n$(INFO)INFO: Removing link_stats.txt...$(END)\n"
+ @rm -rf link_stats.txt
+
build-lunr-index:
@printf "\n$(INFO)INFO: Building offline search index..$(END)\n"
node scripts/lunr/preindex.js
@@ -133,6 +137,10 @@ external-links-check: compile
@printf "\n$(INFO)INFO: Checking all external links...$(END)\n"
@bundle exec nanoc check external_links
+link-stats: clone-all-docs-projects compile clean-link-stats
+ @printf "\n$(INFO)INFO: Generating link statistics report to link_stats.txt...$(END)\n"
+ @bundle exec nanoc check link_stats > link_stats.txt
+
brew-bundle:
@printf "\n$(INFO)INFO: Checking Brew dependencies, if Brew is available...$(END)\n"
@(command -v brew > /dev/null 2>&1) && brew bundle --no-lock || true
diff --git a/doc/testing.md b/doc/testing.md
index f6d2921d..1ad63ce1 100644
--- a/doc/testing.md
+++ b/doc/testing.md
@@ -79,3 +79,17 @@ To test external links, run:
```shell
make external-links-check
```
+
+To generate the link statistics report:
+
+- To a file, run:
+
+ ```shell
+ make link-stats
+ ```
+
+- To your terminal, run:
+
+ ```shell
+ make compile && bundle exec nanoc check link_stats
+ ```
diff --git a/lib/checks/link_stats.rb b/lib/checks/link_stats.rb
new file mode 100644
index 00000000..605d042f
--- /dev/null
+++ b/lib/checks/link_stats.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+COLOR_CODE_RESET = "\e[0m"
+COLOR_CODE_RED = "\e[31m"
+COLOR_CODE_GREEN = "\e[32m"
+
+Nanoc::Check.define(:link_stats) do
+ total_anchor_link_count = 0
+ total_external_link_count = 0
+ total_link_count = 0
+
+ puts "\n#{COLOR_CODE_GREEN}INFO: Generating links statistics report...#{COLOR_CODE_RESET}"
+ output_html_filenames.each do |file|
+ page_anchor_link_count = 0
+ page_external_link_count = 0
+ page_link_count = 0
+ puts "\n#{COLOR_CODE_GREEN}INFO:#{COLOR_CODE_RESET} Processing file: #{file}:"
+ Gitlab::Docs::Page.new(file).links.each do |link|
+ next if link.excluded_link?
+
+ page_anchor_link_count += 1 if link.internal_anchor?
+ page_external_link_count += 1 if link.external?
+ page_link_count += 1
+ puts "#{COLOR_CODE_GREEN}INFO:#{COLOR_CODE_RESET} Found link (#{page_link_count}): #{link.href}"
+ end
+ puts "#{COLOR_CODE_GREEN}INFO:#{COLOR_CODE_RESET} Total number of page links: #{page_link_count} (including: #{page_anchor_link_count} anchors, #{page_external_link_count} external)!"
+ total_anchor_link_count += page_anchor_link_count
+ total_external_link_count += page_external_link_count
+ total_link_count += page_link_count
+ end
+ puts "\n#{COLOR_CODE_GREEN}INFO:#{COLOR_CODE_RESET} Total number of links: #{total_link_count} (including: #{total_anchor_link_count} anchors, #{total_external_link_count} external)!"
+end
diff --git a/lib/gitlab/docs/link.rb b/lib/gitlab/docs/link.rb
index d0e7b9d8..d6c983d2 100644
--- a/lib/gitlab/docs/link.rb
+++ b/lib/gitlab/docs/link.rb
@@ -32,6 +32,43 @@ module Gitlab
@href.length.positive? && !@href.include?(':')
end
+ def external?
+ @href.length.positive? && @href.include?(':')
+ end
+
+ def excluded_link?
+ @href.length.positive? &&
+ (@href.start_with?(
+ '/',
+ 'https://about.gitlab.com/releases/categories/releases',
+ 'https://gitlab.com/-/trial_registrations',
+ 'https://customers.staging.gitlab.com/openapi_docs',
+ 'https://about.gitlab.com/handbook/product/product-intelligence-guide',
+ 'https://metrics.gitlab.com',
+ 'https://gitlab.com/gitlab-org/gitlab-development-kit',
+ 'https://design.gitlab.com/get-started/contributing',
+ 'https://gitlab.com/gitlab-org/gitlab/-/issues/new',
+ '#help-feedback-content',
+ 'https://about.gitlab.com/community/gitlab-first-look',
+ 'https://about.gitlab.com/pricing',
+ 'https://about.gitlab.com/free-trial',
+ 'https://forum.gitlab.com/new-topic',
+ 'https://about.gitlab.com/support',
+ 'https://gitlab.com/dashboard',
+ 'https://twitter.com/gitlab',
+ 'https://www.facebook.com/gitlab',
+ 'https://www.youtube.com/channel',
+ 'https://www.linkedin.com/company/gitlab-com',
+ 'https://gitlab.com/gitlab-org/gitlab-docs',
+ 'https://about.gitlab.com/company',
+ 'https://about.gitlab.com/terms',
+ 'https://about.gitlab.com/privacy',
+ 'https://about.gitlab.com/company/contact',
+ 'https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit',
+ 'https://creativecommons.org/licenses/by-sa/4.0'
+ ) || @href == '#')
+ end
+
def path
@href.partition('#').first
end