Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Show only the latest word and a random word on the homepage. Use base…
Browse files Browse the repository at this point in the history
… tag again.
  • Loading branch information
Sumeet Adur committed Dec 1, 2015
1 parent 0a7da78 commit c36f015
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/.sass-cache/
/.env
/client/words.json
/client/homewords.json
npm-debug.log
12 changes: 6 additions & 6 deletions client/definition-page.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{> top }}
<main>
<h1><a href="../">Guffipedia</a></h1>
<div class="headshot"><img src="../images/lucy.png"></div>
<h1><a href="">Guffipedia</a></h1>
<div class="headshot"><img src="images/lucy.png"></div>
<div class="subheader">Lucy Kellaway's dictionary of business jargon and corporate nonsense</div>
<div class="line"></div>
<a href="../guffipedia-form" class="o-buttons o-buttons--standout">Suggest an entry</a>
<a href="guffipedia-form" class="o-buttons o-buttons--standout">Suggest an entry</a>

<div class="detailed-guff">
<div class="word">
Expand Down Expand Up @@ -43,17 +43,17 @@
{{/if}}
{{#if relatedwords}}
<p class="detail relatedwords">Related:
{{#each relatedwords}}<a href="../{{slug}}/">{{word}}</a>{{#unless @last}}&comma;&nbsp;{{/unless}}{{/each}}
{{#each relatedwords}}<a href="{{slug}}/">{{word}}</a>{{#unless @last}}&comma;&nbsp;{{/unless}}{{/each}}
</p>
{{/if}}
</div>
</div>
<div class="navigate-guff">
{{#if previousWord}}
<a href="../{{previousWord.slug}}/" class="previous-guff">&laquo; Previous<br><span class="preview">{{previousWord.word}}</span></a>
<a href="{{previousWord.slug}}/" class="previous-guff">&laquo; Previous<br><span class="preview">{{previousWord.word}}</span></a>
{{/if}}
{{#if nextWord}}
<a href="../{{nextWord.slug}}/" class="next-guff">Next &raquo;<br><span class="preview">{{nextWord.word}}</span></a>
<a href="{{nextWord.slug}}/" class="next-guff">Next &raquo;<br><span class="preview">{{nextWord.word}}</span></a>
{{/if}}
</div>
</main>
Expand Down
3 changes: 2 additions & 1 deletion client/main-page.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


<ul class="guffs">
{{#each words}}
{{#each homewords}}
<li class="guff">
<h2>{{#if @first}}Latest{{else}}Random{{/if}} Guff</h2>
<a class="word" href="{{@key}}/">{{word}}</a>
<div class="details">
{{#if definition}}
Expand Down
12 changes: 7 additions & 5 deletions client/top.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@

<link rel="shortcut icon" href="https://ig.ft.com/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="//im.ft-static.com/m/icons/apple-touch-icon.png">

{{#if word}}<base href="../" />{{/if}}

<title>{{#if pageTitle}}{{pageTitle}}{{else}}Guffipedia - FT.com{{/if}}</title>
<title>Guffipedia{{#if word}}: “{{word}}{{/if}} - FT.com</title>
<!-- <meta name="description" content="ENTER A DESCRIPTION HERE"> -->

<!-- smoosh -->
<!-- build:js scripts/top.js -->
<script src="{{#if word}}../{{/if}}scripts/top.js"></script>
<script src="scripts/top.js"></script>
<!-- endbuild -->
<!-- endsmoosh -->

<!-- smoosh -->
<!-- build:css styles/top.css -->
<link rel="stylesheet" href="{{#if word}}../{{/if}}styles/top.css">
<link rel="stylesheet" href="styles/top.css">
<!-- endbuild -->
<!-- endsmoosh -->

<!-- build:css styles/main.css -->
<link rel="stylesheet" href="{{#if word}}../{{/if}}bower_components/normalize.css/normalize.css">
<link rel="stylesheet" href="{{#if word}}../{{/if}}styles/main.css">
<link rel="stylesheet" href="bower_components/normalize.css/normalize.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body>
Expand Down
51 changes: 39 additions & 12 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ gulp.task('download-data', () => fetch(`https://bertha.ig.ft.com/republish/publi
for (const row of spreadsheet) {
if (words[row.slug]) throw new Error('Already exists: ' + row.slug);

row.pageTitle = `Guffipedia: “${row.word}” – FT.com`;

words[row.slug] = row;
}

var slugIndex = Object.keys(words).sort();
let wordArray = Object.keys(words);

let slugIndex = wordArray.sort();

for (const row of spreadsheet) {
let currentSlug = row.slug;
Expand All @@ -263,21 +263,46 @@ gulp.task('download-data', () => fetch(`https://bertha.ig.ft.com/republish/publi
};
});

let slugPointer = null;

if (slugIndex.indexOf(currentSlug) > 0) {
words[currentSlug].previousWord = {
slug: words[slugIndex[slugIndex.indexOf(currentSlug)-1]].slug,
word: words[slugIndex[slugIndex.indexOf(currentSlug)-1]].word
};
slugPointer = slugIndex.indexOf(currentSlug)-1;
} else {
slugPointer = slugIndex.length-1;
}

words[currentSlug].previousWord = {
slug: words[slugIndex[slugPointer]].slug,
word: words[slugIndex[slugPointer]].word
};

if (slugIndex.indexOf(currentSlug) < slugIndex.length-1) {
words[currentSlug].nextWord = {
slug: words[slugIndex[slugIndex.indexOf(currentSlug)+1]].slug,
word: words[slugIndex[slugIndex.indexOf(currentSlug)+1]].word
};
slugPointer = slugIndex.indexOf(currentSlug)+1;
} else {
slugPointer = 0;
}

words[currentSlug].nextWord = {
slug: words[slugIndex[slugPointer]].slug,
word: words[slugIndex[slugPointer]].word
};
}

fs.writeFileSync('client/words.json', JSON.stringify(words, null, 2));

let dateIndex = wordArray.sort(function(a, b) {
return new Date(words[b].submissiondate) - new Date(words[a].submissiondate);
});

const homewords = {};

homewords[dateIndex[0]] = words[dateIndex[0]];

let randomNumber = Math.floor(Math.random() * ((dateIndex.length)-1)) + 1;
homewords[dateIndex[randomNumber]] = words[dateIndex[randomNumber]];

fs.writeFileSync('client/homewords.json', JSON.stringify(homewords, null, 2));

})
);

Expand All @@ -297,7 +322,9 @@ gulp.task('templates', () => {
fs.writeFileSync(`.tmp/${slug}/index.html`, html);
}

const homewords = JSON.parse(fs.readFileSync('client/homewords.json', 'utf8'));

const mainPageTemplate = Handlebars.compile(fs.readFileSync('client/main-page.hbs', 'utf8'));
const html = mainPageTemplate({words});
const html = mainPageTemplate({homewords});
fs.writeFileSync(`.tmp/index.html`, html);
});

0 comments on commit c36f015

Please sign in to comment.