Skip to content

Commit 0e6605d

Browse files
committed
feat(index.html): added back-link to crates.io
* url is created per-API and features a nice crates image coming from githubusercontent. Closes #105 [skip ci]
1 parent 5c284e1 commit 0e6605d

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

etc/api/shared.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ make:
1717
types:
1818
- api
1919
- cli
20+
html_index:
21+
asset_urls:
22+
crates_img: https://raw.githubusercontent.com/rust-lang/crates.io/master/public/favicon.ico
2023
directories:
2124
# directory under which all generated sources should reside
2225
output: gen

src/mako/index.html.mako

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%
22
import os
33
import yaml
4-
from util import (gen_crate_dir, api_index)
4+
from util import (gen_crate_dir, api_index, crates_io_url)
55
66
title = 'Google Service Documentation for Rust'
77
@@ -68,6 +68,9 @@ DO NOT EDIT !
6868
% for api_name in type_names:
6969
<% ad = tc[api_name] %>
7070
<a class="mod" href="${api_index(DOC_ROOT, an, v, ad.make)}" title="${ad.make.id.upper()} docs for the ${an} ${v}">${ad.make.id.upper()}</a>
71+
% if api_name == 'api':
72+
<a href="${crates_io_url(an, v)}"><img src="${html_index.asset_urls.crates_img}" title="This API on crates.io" height="16" width="16"/></a>
73+
% endif
7174
% if not loop.last:
7275
,
7376
% endif

src/mako/lib/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ def to_extern_crate_name(crate_name):
832832
def gen_crate_dir(name, version, ti):
833833
return to_extern_crate_name(library_to_crate_name(library_name(name, version), ti.target_suffix))
834834

835+
def crates_io_url(name, version):
836+
return "https://crates.io/crates/%s" % library_to_crate_name(library_name(name, version))
837+
835838
def api_index(DOC_ROOT, name, version, ti, check_exists=True):
836839
crate_dir = gen_crate_dir(name, version, ti)
837840
if ti.documentation_engine == 'rustdoc':

0 commit comments

Comments
 (0)