Skip to content

Commit

Permalink
Handle redirects with a custom 404 page instead of using jekyll-redir…
Browse files Browse the repository at this point in the history
…ect-from.

This allows us to redirect entire subtrees instead of just the root.
All of the short link redirects can be generated in JavaScript when
the website is built, so we longer need to create and check in
hundreds of markdown files.

Also:
- Added badges for the latest and snapshot versions of Javadocs.
- Added a redirect from /releases/latest/ to the latest version.
- Fixed the whitespaces in the generated HTML files.
- Fixed the config so that the website works on local development servers.
- Removed some unused files.
  • Loading branch information
chaoren committed Jan 10, 2025
1 parent 5c2ea70 commit 1259180
Show file tree
Hide file tree
Showing 792 changed files with 165 additions and 4,055 deletions.
12 changes: 12 additions & 0 deletions 404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: default
title: Page Not Found
redirects:
/api: /releases/snapshot-jre/api/docs
/releases/snapshot/: /releases/snapshot-jre/
/releases/latest/: /releases/{{site.latest_release}}-jre/
---

# 404

The requested URL does not exist.
4 changes: 0 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: Guava
subtitle: Google core libraries for Java
description: Google core libraries for Java
baseurl: /
url: https://guava.dev

themeColor: red
Expand All @@ -18,9 +17,6 @@ exclude:
- vendor
- "*.sh"

plugins:
- jekyll-redirect-from

# Release data
# Do not change! updaterelease.sh automatically updates these fields
latest_release: 33.4.0
Expand Down
6 changes: 3 additions & 3 deletions _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% comment %}
{%- comment -%}
Copyright (C) 2018 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -11,8 +11,8 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.foobar2
{% endcomment %}
limitations under the License.
{%- endcomment -%}

<footer class="c-footer">
<div class="u-container c-footer__container">
Expand Down
19 changes: 11 additions & 8 deletions _includes/head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% comment %}
{%- comment -%}
Copyright (C) 2018 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -11,8 +11,8 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.foobar2
{% endcomment %}
limitations under the License.
{%- endcomment -%}

<head>
<meta charset="utf-8">
Expand All @@ -22,12 +22,15 @@
<title>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</title>
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">

{%- if page.redirects %}
{% include redirects.html %}
{%- endif %}

<link href='https://fonts.googleapis.com/css?family=Roboto:400,400italic,700|Roboto+Mono:400,500' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}">
{% if site.googleAnalyticsId %}
<link rel="stylesheet" href="{{ site.baseurl }}/css/main.css">
<link rel="canonical" href="{{ site.url }}{{ site.baseurl }}{{ page.url | replace: "index.html", "" }}">
{%- if site.googleAnalyticsId %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand All @@ -37,5 +40,5 @@
ga('create', '{{ site.googleAnalyticsId }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{%- endif %}
</head>
12 changes: 6 additions & 6 deletions _includes/navigation.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% comment %}
{%- comment -%}
Copyright (C) 2018 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -11,16 +11,16 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.foobar2
{% endcomment %}
limitations under the License.
{%- endcomment -%}

<nav class="c-navigation {% if site.fixedNav == 'true' %}is-fixed{% endif %}">
<div class="c-navigation__container u-container">

{% for i in site.nav %}
{% assign url = i.item.url %}
{%- for i in site.nav %}
{%- assign url = i.item.url %}
<a class="c-navigation__item {% if page.url == url %}is-active{% endif %}" href="{{ url | prepend: site.baseurl }}">{{i.item.name}}</a>
{% endfor %}
{%- endfor %}

</div>
</nav>
51 changes: 51 additions & 0 deletions _includes/redirects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{%- comment -%}
Copyright (C) 2025 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{%- endcomment -%}

<script>
{%- for redirect in page.redirects %}
{%- assign from = redirect[0] %}
{%- assign to = redirect[1] | replace: "{{site.latest_release}}", site.latest_release %}
{%- assign end = from | slice: -1 %}

if (
{%- if end == "/" -%}
location.pathname.startsWith('{{ site.baseurl }}{{ from }}')
{%- else -%}
(location.pathname + '/').startsWith('{{ site.baseurl }}{{ from }}/')
{%- endif -%}
) {
location.pathname = location.pathname.replace('{{ from }}', '{{ to }}');
}

{%- endfor %}

switch (location.pathname.toLowerCase()) {
{%- for file in site.static_files %}
{%- if file.extname == ".html"
and file.path contains "/snapshot-jre/api/docs/com/" %}
{%- unless file.basename contains "-"
or file.basename contains "."
or file.path contains "/class-use/" %}
case '{{ site.baseurl }}/{{ file.basename | downcase }}':
case '{{ site.baseurl }}/{{ file.basename | downcase }}/':
case '{{ site.baseurl }}/{{ file.basename | downcase }}/index.html':
location.pathname = '{{ site.baseurl }}{{ file.path }}';
break;
{%- endunless %}
{%- endif %}
{%- endfor %}
}
</script>
39 changes: 0 additions & 39 deletions _includes/social.html

This file was deleted.

18 changes: 8 additions & 10 deletions _layouts/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% comment %}
{%- comment -%}
Copyright (C) 2018 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,16 +12,14 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
{%- endcomment -%}

<!DOCTYPE html>
<html class="t-{{ site.themeColor }}">
{% include head.html %}
<body>
{% include navigation.html %}

{{ content }}

{% include footer.html %}
</body>
{% include head.html %}
<body>
{% include navigation.html %}
{{ content }}
{% include footer.html %}
</body>
</html>
3 changes: 2 additions & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

layout: base
---

<article class="c-article">
<header class="c-header c-article__header">
<div class="u-container">
Expand All @@ -23,6 +24,6 @@ <h1 class="c-header__title">{{ page.title }}</h1>
</header>

<div class="c-article__main">
{{ content }}
{{ content }}
</div>
</article>
18 changes: 0 additions & 18 deletions _layouts/post.html

This file was deleted.

11 changes: 0 additions & 11 deletions _layouts/redirect.html

This file was deleted.

5 changes: 0 additions & 5 deletions api/index.md

This file was deleted.

36 changes: 36 additions & 0 deletions badge/javadoc/latest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions badge/javadoc/snapshot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed elements/GitHub-Mark-Light-32px.png
Binary file not shown.
Loading

0 comments on commit 1259180

Please sign in to comment.