Skip to content

Commit

Permalink
Update Hugo and Docsy
Browse files Browse the repository at this point in the history
Due to googleforgames#1668, saw that Hugo can fall over with:
`fatal error: concurrent map read and map write`

When there are lots of CPUs, so decided it was time to take the
opportunity to update Hugo.

Only big difference was to enable "unsafe" in the markdown engine, so
that it would allow HTML in markdown.
  • Loading branch information
markmandel committed Jul 6, 2020
1 parent a34f001 commit ed5e42c
Show file tree
Hide file tree
Showing 40 changed files with 657 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.s
# \_/\_/ \___|_.__/|___/_|\__\___|
#

ENV HUGO_VER 0.58.3
ENV HUGO_VER 0.73.0
RUN mkdir /tmp/hugo && \
wget -q -O /tmp/hugo/hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v${HUGO_VER}/hugo_extended_${HUGO_VER}_Linux-64bit.tar.gz && \
tar -zxvf /tmp/hugo/hugo.tar.gz -C /tmp/hugo/ && \
Expand Down
8 changes: 2 additions & 6 deletions site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ pygmentsStyle = "tango"
[permalinks]
blog = "/:section/:year/:month/:day/:slug/"

## Configuration for BlackFriday markdown parser: https://github.com/russross/blackfriday
[blackfriday]
plainIDAnchors = true
hrefTargetBlank = false
angledQuotes = false
latexDashes = true
[markup.goldmark.renderer]
unsafe = true

# Image processing configuration.
[imaging]
Expand Down
6 changes: 6 additions & 0 deletions site/themes/docsy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ information on using pull requests.

This project follows
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).

## How to contribute

See the [contribution
guidelines](https://www.docsy.dev/docs/contribution-guidelines/)
in the Docsy user guide.
188 changes: 188 additions & 0 deletions site/themes/docsy/assets/js/offline-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Adapted from code by Matt Walters https://www.mattwalters.net/posts/hugo-and-lunr/

(function ($) {
'use strict';

$(document).ready(function () {
const $searchInput = $('.td-search-input');

//
// Options for popover
//

$searchInput.data('html', true);
$searchInput.data('placement', 'bottom');
$searchInput.data(
'template',
'<div class="popover offline-search-result" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
);

//
// Register handler
//

$searchInput.on('change', (event) => {
render($(event.target));

// Hide keyboard on mobile browser
$searchInput.blur();
});

// Prevent reloading page by enter key on sidebar search.
$searchInput.closest('form').on('submit', () => {
return false;
});

//
// Lunr
//

let idx = null; // Lunr index
const resultDetails = new Map(); // Will hold the data for the search results (titles and summaries)

// Set up for an Ajax call to request the JSON data file that is created by Hugo's build process
$.ajax($searchInput.data('offline-search-index-json-src')).then(
(data) => {
idx = lunr(function () {
this.ref('ref');
this.field('title', { boost: 2 });
this.field('body');

data.forEach((doc) => {
this.add(doc);

resultDetails.set(doc.ref, {
title: doc.title,
excerpt: doc.excerpt,
});
});
});

$searchInput.trigger('change');
}
);

const render = ($targetSearchInput) => {
// Dispose the previous result
$targetSearchInput.popover('dispose');

//
// Search
//

if (idx === null) {
return;
}

const searchQuery = $targetSearchInput.val();
if (searchQuery === '') {
return;
}

const results = idx
.query((q) => {
const tokens = lunr.tokenizer(searchQuery.toLowerCase());
tokens.forEach((token) => {
const queryString = token.toString();
q.term(queryString, {
boost: 100,
});
q.term(queryString, {
wildcard:
lunr.Query.wildcard.LEADING |
lunr.Query.wildcard.TRAILING,
boost: 10,
});
q.term(queryString, {
editDistance: 2,
});
});
})
.slice(
0,
$targetSearchInput.data('offlnie-search-max-results')
);

//
// Make result html
//

const $html = $('<div>');

$html.append(
$('<div>')
.css({
display: 'flex',
justifyContent: 'space-between',
marginBottom: '1em',
})
.append(
$('<span>')
.text('Search results')
.css({ fontWeight: 'bold' })
)
.append(
$('<i>')
.addClass('fas fa-times search-result-close-button')
.css({
cursor: 'pointer',
})
)
);

const $searchResultBody = $('<div>').css({
maxHeight: `calc(100vh - ${
$targetSearchInput.offset().top -
$(window).scrollTop() +
180
}px)`,
overflowY: 'auto',
});
$html.append($searchResultBody);

if (results.length === 0) {
$searchResultBody.append(
$('<p>').text(`No results found for query "${searchQuery}"`)
);
} else {
results.forEach((r) => {
const doc = resultDetails.get(r.ref);
const href =
$searchInput.data('offline-search-base-href') +
r.ref.replace(/^\//, '');

const $entry = $('<div>').addClass('mt-4');

$entry.append(
$('<small>').addClass('d-block text-muted').text(r.ref)
);

$entry.append(
$('<a>')
.addClass('d-block')
.css({
fontSize: '1.2rem',
})
.attr('href', href)
.text(doc.title)
);

$entry.append($('<p>').text(doc.excerpt));

$searchResultBody.append($entry);
});
}

$targetSearchInput.on('shown.bs.popover', () => {
$('.search-result-close-button').on('click', () => {
$targetSearchInput.val('');
$targetSearchInput.trigger('change');
});
});

$targetSearchInput
.data('content', $html[0].outerHTML)
.popover('show');
};
});
})(jQuery);
15 changes: 14 additions & 1 deletion site/themes/docsy/assets/scss/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@
}

font-family: "Font Awesome 5 Free", $font-family-base;
}
}

.popover.offline-search-result {
// Override bootstrap default style (max-width: $popover-max-width;)
max-width: 90%;

.card {
margin-bottom: $spacer * .5;

.card-header {
font-weight: bold;
}
}
}
5 changes: 5 additions & 0 deletions site/themes/docsy/assets/scss/_sidebar-tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
padding: 0 0 1rem;
}
}

& > .td-sidebar-nav__section {
padding-top: .5rem;
padding-left: 1.5rem;
}
}

.td-sidebar {
Expand Down
6 changes: 3 additions & 3 deletions site/themes/docsy/assets/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $td-sidebar-border-color: $border-color !default;
// Background colors for the sections on home page etc. It is a paint by number system, starting at 0, where the number is taken from the shortcode's ordinal
// if not provided by the user.
// These colors are all part of the theme palette, but the mix is fairly random to create variation. This can be overridden by the project if needed.
$td-box-colors: $dark, $primary, $secondary, $info, $primary-light, $gray-600, $success, $warning, $dark, $danger, $primary, $secondary, $primary-light, $info;
$td-box-colors: $dark, $primary, $secondary, $info, $primary-light, $gray-600, $success, $warning, $dark, $danger, $primary, $secondary, $primary-light, $info !default;

$link-color: darken($blue, 15%) !default;
$link-decoration: none !default;
Expand Down Expand Up @@ -110,8 +110,8 @@ $display4-size: 1.75rem !default;
// Space

$spacer: 1rem;
$td-block-space-top-base: 4 * $spacer;
$td-block-space-bottom-base: 4 * $spacer;
$td-block-space-top-base: 4 * $spacer !default;
$td-block-space-bottom-base: 4 * $spacer !default;

// Pagination

Expand Down
7 changes: 6 additions & 1 deletion site/themes/docsy/assets/scss/blocks/_cover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
size: cover;
};

}
& > .byline {
position: absolute;
bottom: 2px;
right: 4px;
}
}
4 changes: 4 additions & 0 deletions site/themes/docsy/assets/scss/support/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#{$parent} {
color: $color;

&:hover {
color: $hover-color;
}

@if $underline {
text-decoration: underline;
}
Expand Down
43 changes: 43 additions & 0 deletions site/themes/docsy/i18n/es.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


# UI strings. Botones y similares.

[ui_pager_prev]
other = "Previo"

[ui_pager_next]
other = "Siguiente"

[ui_read_more]
other = "Contiuar leyendo"

[ui_search]
other = "Buscar"

# Used in sentences such as "Posted in News"
[ui_in]
other = "en"

# Footer text
[footer_all_rights_reserved]
other = "Derechos reservados"

[footer_privacy_policy]
other = "Política de privacidad"


# Post (blog, articles etc.)
[post_byline_by]
other = "Por"
[post_created]
other = "Creado"
[post_last_mod]
other = "Última modificación"
[post_edit_this]
other = "Editar esta página"
[post_create_issue]
other = "Notificar una incidencia con la documentanción"
[post_create_project_issue]
other = "Notificar una incidencia en un proyecto"
[post_posts_in]
other = "Añadir entrada"
43 changes: 43 additions & 0 deletions site/themes/docsy/i18n/fr.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


# UI strings. Buttons and similar.

[ui_pager_prev]
other = "Précédent"

[ui_pager_next]
other = "Suivant"

[ui_read_more]
other = "Lire plus"

[ui_search]
other = "Rechercher ce site…"

# Used in sentences such as "Posted in News"
[ui_in]
other = "dans"

# Footer text
[footer_all_rights_reserved]
other = "Tous droits résérvés"

[footer_privacy_policy]
other = "Politique de confidentialité"


# Post (blog, articles etc.)
[post_byline_by]
other = "Par"
[post_created]
other = "Crée"
[post_last_mod]
other = "Dernière modification"
[post_edit_this]
other = "Modifier cette page"
[post_create_issue]
other = "Créer un problème dans la documentation"
[post_create_project_issue]
other = "Créer un problème dans le projet"
[post_posts_in]
other = "Messages dans"
Loading

0 comments on commit ed5e42c

Please sign in to comment.