Skip to content

Commit 971d2c6

Browse files
committed
Merge branch 'master' into typo-fixes
2 parents f3898a0 + 22ae797 commit 971d2c6

29 files changed

+366
-69
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV ENABLE_SERVICE_WORKER=true
66
WORKDIR /devdocs
77

88
RUN apt-get update && \
9-
apt-get -y install git nodejs && \
9+
apt-get -y install git nodejs libcurl4 && \
1010
gem install bundler && \
1111
rm -rf /var/lib/apt/lists/*
1212

Dockerfile-alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WORKDIR /devdocs
77

88
COPY . /devdocs
99

10-
RUN apk --update add nodejs build-base libstdc++ gzip git zlib-dev && \
10+
RUN apk --update add nodejs build-base libstdc++ gzip git zlib-dev libcurl && \
1111
gem install bundler && \
1212
bundle install --system --without test && \
1313
thor docs:download --all && \

assets/javascripts/app/app.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
.install()
7979
@previousErrorHandler = onerror
8080
window.onerror = @onWindowError.bind(@)
81-
CookieStore.onBlocked = @onCookieBlocked
81+
CookiesStore.onBlocked = @onCookieBlocked
8282
return
8383

8484
bootOne: ->

assets/javascripts/app/config.coffee.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ app.config =
1313
version: <%= Time.now.to_i %>
1414
release: <%= Time.now.utc.httpdate.to_json %>
1515
mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
16+
favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'
1617
service_worker_path: '/service-worker.js'
1718
service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>

assets/javascripts/app/settings.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class app.Settings
3333
analyticsConsent: false
3434

3535
constructor: ->
36-
@store = new CookieStore
36+
@store = new CookiesStore
3737
@cache = {}
3838

3939
get: (key) ->

assets/javascripts/lib/cookie_store.coffee renamed to assets/javascripts/lib/cookies_store.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
class @CookieStore
1+
class @CookiesStore
2+
# Intentionally called CookiesStore instead of CookieStore
3+
# Calling it CookieStore causes issues when the Experimental Web Platform features flag is enabled in Chrome
4+
# Related issue: https://github.com/freeCodeCamp/devdocs/issues/932
5+
26
INT = /^\d+$/
37

48
@onBlocked: ->

assets/javascripts/lib/favicon.coffee

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
defaultUrl = null
2+
currentSlug = null
3+
4+
imageCache = {}
5+
urlCache = {}
6+
7+
withImage = (url, action) ->
8+
if imageCache[url]
9+
action(imageCache[url])
10+
else
11+
img = new Image()
12+
img.crossOrigin = 'anonymous'
13+
img.src = url
14+
img.onload = () =>
15+
imageCache[url] = img
16+
action(img)
17+
18+
@setFaviconForDoc = (doc) ->
19+
return if currentSlug == doc.slug
20+
21+
favicon = $('link[rel="icon"]')
22+
23+
if defaultUrl == null
24+
defaultUrl = favicon.href
25+
26+
if urlCache[doc.slug]
27+
favicon.href = urlCache[doc.slug]
28+
currentSlug = doc.slug
29+
return
30+
31+
styles = window.getComputedStyle($("._icon-#{doc.slug.split('~')[0]}"), ':before')
32+
33+
bgUrl = app.config.favicon_spritesheet
34+
sourceSize = 16
35+
sourceX = Math.abs(parseInt(styles['background-position-x'].slice(0, -2)))
36+
sourceY = Math.abs(parseInt(styles['background-position-y'].slice(0, -2)))
37+
38+
withImage(bgUrl, (docImg) ->
39+
withImage(defaultUrl, (defaultImg) ->
40+
size = defaultImg.width
41+
42+
canvas = document.createElement('canvas')
43+
ctx = canvas.getContext('2d')
44+
45+
canvas.width = size
46+
canvas.height = size
47+
ctx.drawImage(defaultImg, 0, 0)
48+
49+
docIconPercentage = 65
50+
destinationCoords = size / 100 * (100 - docIconPercentage)
51+
destinationSize = size / 100 * docIconPercentage
52+
ctx.drawImage(docImg, sourceX, sourceY, sourceSize, sourceSize, destinationCoords, destinationCoords, destinationSize, destinationSize)
53+
54+
urlCache[doc.slug] = canvas.toDataURL()
55+
favicon.href = urlCache[doc.slug]
56+
57+
currentSlug = doc.slug
58+
)
59+
)
60+
61+
@resetFavicon = () ->
62+
if defaultUrl != null and currentSlug != null
63+
$('link[rel="icon"]').href = defaultUrl
64+
currentSlug = null

assets/javascripts/views/content/content.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class app.views.Content extends app.View
153153
return
154154

155155
afterRoute: (route, context) =>
156+
if route != 'entry' and route != 'type'
157+
resetFavicon()
158+
156159
switch route
157160
when 'root'
158161
@show @rootPage

assets/javascripts/views/content/entry_page.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class app.views.EntryPage extends app.View
4040
if app.disabledDocs.findBy 'slug', @entry.doc.slug
4141
@hiddenView = new app.views.HiddenPage @el, @entry
4242

43+
setFaviconForDoc(@entry.doc)
4344
@delay @polyfillMathML
4445
@trigger 'loaded'
4546
return

assets/javascripts/views/content/type_page.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class app.views.TypePage extends app.View
99

1010
render: (@type) ->
1111
@html @tmpl('typePage', @type)
12+
setFaviconForDoc(@type.doc)
1213
return
1314

1415
getTitle: ->

0 commit comments

Comments
 (0)