Skip to content

Commit 7fd5e97

Browse files
committed
Cherry-pick #33 from eecs485staff/enhancement/pr-preview
1 parent a95e52e commit 7fd5e97

File tree

8 files changed

+44
-11
lines changed

8 files changed

+44
-11
lines changed

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ PROJECT_ROOT=`dirname $GITHOOKS_DIR`
1010

1111
set -x
1212

13-
npx webpack --env prod
13+
npx webpack --env.production
1414
git add $PROJECT_ROOT/assets/js/primer_spec_plugin.min.js

_layouts/spec.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<!-- BEGIN CUSTOM SPEC CODE -->
99
{% if jekyll.environment == "dev" %}
1010
{% assign base_url = "http://localhost:4000" %}
11+
{% elsif jekyll.environment == "site-preview" %}
12+
{% assign url_size = site.url | size | minus: 1 %}
13+
{% assign base_url = site.url | slice: 0, url_size %}
1114
{% else %}
1215
{% assign base_url = "https://eecs485staff.github.io/primer-spec" %}
1316
{% endif %}

index.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Due: ~~8pm, Apr 1, 2019~~ **Anytime!** _This is an individual project._
1111
# Introduction
1212
In Computer Science courses, project specifications tend to get [really](https://web.archive.org/web/20180425010014/https://eecs485staff.github.io/p3-insta485-clientside/) [long](https://web.archive.org/web/20190424183409/https://eecs280staff.github.io/p3-euchre/). The intention for such a long document is good — they usually provide all the information that a student would need to successfully complete the project. However, this can also make it difficult for students to find information quickly — they often get lost in the document, and cannot easily find the information they need on the fly.
1313

14-
<!-- <img src="https://gdurl.com/npWU" alt="Infinite scroll..." height="250"/> -->
15-
1614
| <img src="https://media.giphy.com/media/vvWhQsVAFkyisScAsM/200w_d.gif" alt="Infinite scroll..." height="150"/> |
1715
|:--:|
1816
| _Infinite scroll..._ |
@@ -74,7 +72,7 @@ $ python3 -m http.server
7472

7573
Visit [http://localhost:8000](http://localhost:8000) on your web browser. The page should look similar to this screenshot:
7674

77-
<img src="https://gdurl.com/1Kq10" height="250" alt="project page without sidebar" />
75+
<img src="https://drive.google.com/uc?export=view&id=1Kplxw_Eb7343xLFGXTcpjNpsay9GraMe" height="250" alt="project page without sidebar" />
7876

7977
The spec already looks pretty good, but it could certainly be improved with a sidebar.
8078

@@ -83,7 +81,7 @@ In this section, you will add a sidebar to the HTML page and hard-code its conte
8381

8482
When you're done with this section, your webpage will have a sidebar on the left, something like this screenshot:
8583

86-
<img src="https://gdurl.com/zJi1" height="250" alt="project page with sidebar" />
84+
<img src="https://drive.google.com/uc?export=view&id=1_QPsSGlXKjfqY-3TUbsXej5isOZypK7U" height="250" alt="project page with sidebar" />
8785

8886
Of course, _your_ finished webpage doesn't have to look like this. After all, this project isn't autograded! (In fact, feel free to showcase your project spec design with us! Create an issue on [our GitHub repository](https://github.com/eecs485staff/primer-spec/issues) with a screenshot of your design.)
8987

script/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
set -e
55

6-
npx webpack --env dev
6+
npx webpack
77
JEKYLL_ENV=dev bundle exec jekyll build

script/ci-site-preview-build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# Build a preview of the theme, only to be used in conjunction with
3+
# Primer Spec Preview.
4+
5+
set -e
6+
7+
if [ "$#" != 1 ]; then
8+
echo "Usage: $0 BASE_URL"
9+
exit 1
10+
fi
11+
BASE_URL="$1"
12+
13+
npx webpack --env.base_url="$BASE_URL"
14+
JEKYLL_ENV=site-preview bundle exec jekyll build

script/cibuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
npx webpack --env prod
5+
npx webpack --env.production
66
JEKYLL_ENV=prod bundle exec jekyll build
77
bundle exec htmlproofer ./_site --check-html --url-ignore "/web.archive.org/,/localhost/"
88
bundle exec rubocop -D

script/server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
# command in the background is killed also.
88
# Based on https://unix.stackexchange.com/a/204619
99
trap 'kill %1' SIGINT
10-
npx webpack --env dev --watch &
10+
npx webpack --watch &
1111
JEKYLL_ENV=dev bundle exec jekyll serve
1212
# Finally, undo the trap.
1313
trap - SIGINT

webpack.config.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,26 @@ const DEV_URL = 'http://localhost:4000';
2727
const PROD_URL = 'https://eecs485staff.github.io/primer-spec';
2828
const VERSION = fs.readFileSync(path.resolve(__dirname, 'VERSION'), 'utf-8');
2929

30+
function getBaseURL(env) {
31+
let base_url;
32+
if (env && env.production) {
33+
base_url = PROD_URL;
34+
}
35+
else if (env && env.base_url && typeof env.base_url === 'string') {
36+
base_url = env.base_url;
37+
if (base_url.endsWith('/')) {
38+
base_url = base_url.slice(0, -1);
39+
}
40+
}
41+
else {
42+
base_url = DEV_URL;
43+
}
44+
console.log(`Using base URL: ${base_url}`);
45+
return base_url;
46+
}
47+
3048
module.exports = env => ({
31-
mode: env === PROD_ENV ? 'production' : 'development',
49+
mode: (env && env.production) ? 'production' : 'development',
3250
context: path.resolve(__dirname, 'src_js/'),
3351
entry: './main.ts',
3452
output: {
@@ -65,7 +83,7 @@ module.exports = env => ({
6583
options: {
6684
data: {
6785
// These variables are passed to the liquid templates.
68-
'base_url': env === PROD_ENV ? PROD_URL : DEV_URL,
86+
'base_url': getBaseURL(env),
6987
'primer_spec_version': VERSION,
7088
}
7189
}
@@ -87,7 +105,7 @@ module.exports = env => ({
87105
// These variables become available in any file
88106
new webpack.DefinePlugin({
89107
'process.env.AVAILABLE_SUBTHEMES': `'${AVAILABLE_SUBTHEMES}'`,
90-
'process.env.BASE_URL': `'${env === PROD_ENV ? PROD_URL : DEV_URL}'`,
108+
'process.env.BASE_URL': `'${getBaseURL(env)}'`,
91109
}),
92110
],
93111
// Minimize output

0 commit comments

Comments
 (0)