Skip to content

Commit f1e8a7f

Browse files
committed
Add direct link to recipe file on GitHub
Fixes #24
1 parent 77be78f commit f1e8a7f

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

backend/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ app.get('/sample/cookbook', async (request: express.Request, response: express.R
8282
return;
8383
})
8484

85-
function renderRecipe(req: express.Request, res: express.Response, stars: number, recipe: Recipe) {
85+
function renderRecipe(req: express.Request, res: express.Response, stars: number, recipe: Recipe, fileLocation: string) {
8686
res.render('pages/recipe', {
8787
recipeId: `g/${req.params.username}/${req.params.repo}`,
8888
data: JSON.stringify(recipe),
89-
stars
89+
stars,
90+
fileLocation,
9091
});
9192
}
9293

@@ -117,7 +118,7 @@ app.get('/g/:username/:repo', async (request: express.Request, response: express
117118
const recipeFetch = await fetch(github.getDefaultRecipeUrl(username, repo), {})
118119
const recipeData = await recipeFetch.json()
119120
await searchEng.storeResult(`${username}/${repo}`, recipeData)
120-
renderRecipe(request, response, stars, recipeData)
121+
renderRecipe(request, response, stars, recipeData, '.recipe.json')
121122
} catch(e) {
122123
console.warn(`Could not find default recipe file`, e)
123124
// Try to render the cookbook
@@ -153,7 +154,7 @@ app.get('/g/:username/:repo/:recipe', async (request: express.Request, response:
153154
const recipeData = await recipeFetch.text()
154155
const recipeJson = preprocessRecipeYaml(fileLocation, recipeData)
155156
await searchEng.storeResult(`${username}/${repo}/${recipe}`, recipeJson)
156-
renderRecipe(request, response, stars, recipeJson)
157+
renderRecipe(request, response, stars, recipeJson, fileLocation)
157158
} catch (e) {
158159
console.error(e)
159160
response.status(404).send(`Cannot find. Error: ${e}`)

backend/views/pages/recipe.ejs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
Loading recipe...
1111
</div>
1212

13-
<recipe-body recipe-id="<%= recipeId %>" recipe-data="<%= data %>" stars="<%= stars %>">
13+
<recipe-body
14+
recipe-id="<%= recipeId %>"
15+
recipe-data="<%= data %>"
16+
stars="<%= stars %>"
17+
file="<%= fileLocation %>">
1418
</recipe-body>
1519
</body>
1620
</html>

frontend/recipe.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ class Recipe extends PolymerElement {
8787
</style>
8888
<title-bar stars='[[stars]]' recipe-id='[[recipeId]]' label='[[data.recipe]]'></title-bar>
8989
<styled-card>
90-
<h1>[[data.recipe]]</h1>
90+
<h1>
91+
[[data.recipe]]
92+
<a href="[[sourceUrl]]">
93+
<iron-icon icon="code"></iron-icon>
94+
</a>
95+
</h1>
9196
<small>[[hashtags]]</small><br><br>
9297
<em>Recipe by [[data.author]]</em><br><br>
9398
Serves
@@ -209,6 +214,10 @@ class Recipe extends PolymerElement {
209214
'recipeData': {
210215
type: String,
211216
reflectToAttribute: true,
217+
},
218+
file: {
219+
type: String,
220+
reflectToAttribute: true,
212221
}
213222
};
214223
}
@@ -235,7 +244,8 @@ class Recipe extends PolymerElement {
235244
// GitHub
236245
this.author = recipeElements[1];
237246
this.recipeName = recipeElements[2];
238-
this.forkLink = `https://github.com/${this.author}/${this.recipeName}`;
247+
this.forkLink = `https://github.com/${this.author}/${this.recipeName}`
248+
this.sourceUrl = `https://github.com/${this.author}/${this.recipeName}/blob/master/${this.file}`
239249
}
240250

241251
this.data = JSON.parse(this.recipeData);

0 commit comments

Comments
 (0)