Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment variables to project #1178

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

danielmatthew
Copy link
Contributor

A first pass. In #937 I'd seen reference to #966, so in development mode we don't pull in the service worker partial, nor the analytics.

Before:

<head>
  <script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
  <script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-2419836-9"></script>
  <script></script>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  [ Truncated… ]
  <link rel="sitemap" type="application/xml" title="The A11Y Project" href="/sitemap.xml"><link rel="author" href="humans.txt">
  <script async="">if ('serviceWorker' in navigator) {
		window.addEventListener('load', () => {
			navigator.serviceWorker.register("/sw.js");
		});
	}
  </script>
</head>

After:

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1">
   [ Truncated… ]
  <link rel="sitemap" type="application/xml" title="The A11Y Project" href="/sitemap.xml"><link rel="author" href="humans.txt">
</head>

Closes #937

Use value of ELEVENTY_ENV to load analytics and service worker partials
if we are anything other than in 'development' mode
@boring-cyborg boring-cyborg bot added javascript Issues dealing with JavaScript. markup Issues dealing with markup node Issues dealing with Node.js. labels Jan 17, 2021
@danielmatthew
Copy link
Contributor Author

Ugh… that merge conflict :/

@@ -9,8 +12,10 @@
<link rel="stylesheet" as="style" href="{{ '/css/screen.min.css?v=' + getCurrentVersion.version | url }}" />
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}" />
<link rel="sitemap" type="application/xml" title="{{ metadata.title }}" href="{{ '/sitemap.xml' | url }}" />
<link rel="author" href="/humans.txt" />
{% include "meta/service-worker.njk" %}
<link rel="author" href="humans.txt" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, sorry, I hadn't spied the forward slash when I fixed a conflict.

require('dotenv').config();

module.exports = {
environment: process.env.ELEVENTY_ENV || 'development'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to be set to something other than 'development' over on Netlify… 

@SaptakS
Copy link
Member

SaptakS commented Mar 17, 2021

@danielmatthew Thanks for the work! I reviewed the code and it works perfectly to include the service worker and the analytics only if the environment variable is not labelled development. I think we can add a bit more things to the envionment variables. For example, a lot of the information in src/_data/metadata.json I feel should be configurable by environment variables, like the url, logo, title, etc. Other than that, looks good to me.

Also, you will need to resolve the merge conflict again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Issues dealing with JavaScript. markup Issues dealing with markup node Issues dealing with Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up environment variables
2 participants