Skip to content

Commit 4544982

Browse files
authored
jekyll(last_modified_at): fix for remote resources and data files (docker#15998)
* Dockerfile: add option to enforce git log history for local dev Signed-off-by: CrazyMax <[email protected]> * jekyll(last_modified_at): do not override if already set with frontmatter Signed-off-by: CrazyMax <[email protected]> * jekyll(last_modified_at): use data files for commands reference instead of stub file Signed-off-by: CrazyMax <[email protected]> * fix broken links Signed-off-by: CrazyMax <[email protected]> Signed-off-by: CrazyMax <[email protected]> Co-authored-by: CrazyMax <[email protected]>
1 parent 5fe17fc commit 4544982

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ARG BUNDLER_VERSION=2.3.13
1111

1212
ARG JEKYLL_ENV=development
1313
ARG DOCS_URL=http://localhost:4000
14+
ARG DOCS_ENFORCE_GIT_LOG_HISTORY=0
1415

1516
# Base stage for building
1617
FROM ruby:${RUBY_VERSION}-alpine AS base
@@ -45,6 +46,7 @@ COPY --from=vendored /out /
4546
FROM gem AS generate
4647
ARG JEKYLL_ENV
4748
ARG DOCS_URL
49+
ARG DOCS_ENFORCE_GIT_LOG_HISTORY
4850
ENV TARGET=/out
4951
RUN --mount=type=bind,target=.,rw \
5052
--mount=type=cache,target=/tmp/docker-docs-clone \

_plugins/fetch_remote.rb

+10-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def pre_read(site)
4141
beginning_time = Time.now
4242
puts "Starting plugin fetch_remote.rb..."
4343

44-
fetch_depth = get_docs_url == "http://localhost:4000" ? 1 : 0
44+
fetch_depth = get_docs_url == "http://localhost:4000" && ENV['DOCS_ENFORCE_GIT_LOG_HISTORY'] == "0" ? 1 : 0
4545
site.config['fetch-remote'].each do |entry|
4646
puts " Repo #{entry['repo']}"
4747

@@ -51,10 +51,16 @@ def pre_read(site)
5151
puts " Opening #{clonedir}"
5252
begin
5353
git = Git.open(clonedir)
54-
puts " Fetching #{entry['ref']}"
55-
git.fetch
56-
git.checkout(entry['ref'])
54+
puts " Fetch repository"
55+
if fetch_depth > 0
56+
git.fetch('origin', prune: true, depth: fetch_depth)
57+
else
58+
git.fetch('origin', prune: true)
59+
end
60+
puts " Checkout #{entry['ref']}"
61+
git.checkout(entry['ref'], force: true)
5762
rescue => e
63+
puts " WARNING: #{e}"
5864
FileUtils.rm_rf(clonedir)
5965
puts " Cloning repository into #{clonedir}"
6066
git = Git.clone("#{entry['repo']}.git", Pathname.new(clonedir), branch: entry['ref'], depth: fetch_depth)

_plugins/last_modified_at.rb

+32-8
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,51 @@
55
module Jekyll
66
class LastModifiedAt < Octopress::Hooks::Site
77
DATE_FORMAT = '%Y-%m-%d %H:%M:%S %z'
8-
def pre_render(site)
9-
if get_docs_url == "http://localhost:4000"
10-
# Do not generate last_modified_at for local development
11-
return
8+
9+
def current_last_modified_at(site, page)
10+
if page.data.key?('last_modified_at')
11+
return page.data['last_modified_at']
1212
end
13+
site.config['defaults'].map do |set|
14+
if set['values'].key?('last_modified_at') && set['scope']['path'].include?(page.relative_path)
15+
return set['values']['last_modified_at']
16+
end
17+
end.compact
18+
nil
19+
end
1320

21+
def pre_render(site)
1422
beginning_time = Time.now
1523
Jekyll.logger.info "Starting plugin last_modified_at.rb..."
1624

1725
git = Git.open(site.source)
18-
site.pages.each do |page|
26+
use_file_mtime = get_docs_url == "http://localhost:4000" && ENV['DOCS_ENFORCE_GIT_LOG_HISTORY'] == "0"
27+
site.pages.sort!{|l,r| l.relative_path <=> r.relative_path }.each do |page|
1928
next if page.relative_path == "redirect.html"
2029
next unless File.extname(page.relative_path) == ".md" || File.extname(page.relative_path) == ".html"
21-
unless page.data.key?('last_modified_at')
30+
page.data['last_modified_at'] = current_last_modified_at(site, page)
31+
set_mode = "frontmatter"
32+
path_override = ""
33+
if page.data['last_modified_at'].nil?
34+
page_relative_path = page.relative_path
35+
if page.data.key?('datafolder') && page.data.key?('datafile')
36+
page_relative_path = File.join('_data', page.data['datafolder'], "#{page.data['datafile']}.yaml")
37+
path_override = "\n override: #{page_relative_path}"
38+
end
2239
begin
23-
page.data['last_modified_at'] = git.log.path(page.relative_path).first.date.strftime(DATE_FORMAT)
40+
if use_file_mtime
41+
# Use file's mtime for local development
42+
page.data['last_modified_at'] = File.mtime(page_relative_path).strftime(DATE_FORMAT)
43+
set_mode = "mtime"
44+
else
45+
page.data['last_modified_at'] = git.log.path(page_relative_path).first.date.strftime(DATE_FORMAT)
46+
set_mode = "git"
47+
end
2448
rescue => e
2549
# Ignored
2650
end
2751
end
28-
puts" #{page.relative_path}\n last_modified_at: #{page.data['last_modified_at']}"
52+
puts" #{page.relative_path}#{path_override}\n last_modified_at(#{set_mode}): #{page.data['last_modified_at']}"
2953
end
3054

3155
end_time = Time.now

docker-bake.hcl

+4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ variable "DOCS_URL" {
77
variable "DOCS_SITE_DIR" {
88
default = "_site"
99
}
10+
variable "DOCS_ENFORCE_GIT_LOG_HISTORY" {
11+
default = "0"
12+
}
1013

1114
target "_common" {
1215
args = {
1316
JEKYLL_ENV = JEKYLL_ENV
1417
DOCS_URL = DOCS_URL
18+
DOCS_ENFORCE_GIT_LOG_HISTORY = DOCS_ENFORCE_GIT_LOG_HISTORY
1519
}
1620
no-cache-filter = ["generate"]
1721
}

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
args:
1212
- JEKYLL_ENV
1313
- DOCS_URL
14+
- DOCS_ENFORCE_GIT_LOG_HISTORY
1415
context: .
1516
image: docs/docstage
1617
ports:

subscription/faq.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ When you downgrade your Pro or Team plan, changes are applied at the end of your
9696

9797
### How do I downgrade from a Team plan to a Free Team plan?
9898

99-
Before you downgrade to a Free plan, ensure that your organization details are updated to reflect features available in the Free plan. For example, you may need to reduce the number of team members and convert any private repositories to public repositories. For information on what’s included in the Free plan, see the [billing](index.md#pricing-plans){:target="blank" rel="noopener" class=""} page.
99+
Before you downgrade to a Free plan, ensure that your organization details are updated to reflect features available in the Free plan. For example, you may need to reduce the number of team members and convert any private repositories to public repositories. For information on what’s included in the Free plan, see the [billing](index.md){:target="blank" rel="noopener" class=""} page.
100100

101101
### How do I downgrade from Pro to a Free plan?
102102

@@ -141,8 +141,7 @@ Team starts at $25 per month for the first five users and $7 per month for each
141141
### How will the new pricing plan impact existing Docker Hub customers?
142142

143143
Legacy individual and organizational repository customers have until their January 2021 billing cycle to switch to the new pricing plans.
144-
To view the status of your individual repository plan, see [the billing](https://
145-
hub.docker.com/billing/plan/update){:target="blank" rel="noopener" class=""} page.
144+
To view the status of your individual repository plan, see [the billing](https://hub.docker.com/billing/plan/update){:target="blank" rel="noopener" class=""} page.
146145
To view the status of your organizational repository plan, see [Docker Hub Orgs](https://hub.docker.com/orgs){:target="blank" rel="noopener" class=""} page.
147146

148147
### What is the difference between the legacy repository plans and the newly announced plans?

0 commit comments

Comments
 (0)