Skip to content

Commit 6c00423

Browse files
committed
Switch redirecting over to something more principled
1 parent 7f7fbc2 commit 6c00423

File tree

9 files changed

+327
-290
lines changed

9 files changed

+327
-290
lines changed

_config.yml

Lines changed: 281 additions & 0 deletions
Large diffs are not rendered by default.

conversion/convert-toc-to-redirects.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,32 @@
88

99
var _ = require('underscore');
1010
var nameToId = require('../scripts/nameToId.js');
11+
var idToName = {};
12+
_.each(nameToId, function(id, name) {
13+
idToName[id] = name;
14+
});
1115
var oldToc = require('./old-toc.js');
1216

17+
// these point to X.html
18+
var idsToPagesWithNoHash = {};
19+
// these point to X.html#name where name is generated from id below
1320
var idsToPages = {};
1421

1522
runList = (dir, as) => {
1623
_.each(as, a => {
24+
var aId;
1725
if (!_.isArray(a) && _.isObject(a)){
26+
aId = a.id;
1827
a = a.name;
1928
}
2029

2130
if (_.isString(a)) {
22-
currFile = `${dir}/${a.toLowerCase()}.html`;
31+
var name = a.toLowerCase();
32+
currFile = `${dir}/${name}.html`;
33+
idsToPagesWithNoHash[name] = currFile;
34+
if (aId) {
35+
idsToPagesWithNoHash[aId] = currFile;
36+
}
2337
} else {
2438
addIds = (ids) => {
2539
_.each(ids, (id) => {
@@ -32,7 +46,8 @@ runList = (dir, as) => {
3246
}
3347
id = id.id || id.name;
3448
}
35-
idsToPages[nameToId[id] || id] = currFile;
49+
var ourId = (nameToId[id] || id).toLowerCase();
50+
idsToPages[ourId] = currFile;
3651
}
3752
});
3853
}
@@ -42,10 +57,24 @@ runList = (dir, as) => {
4257
};
4358

4459
runList('api', oldToc[2]);
45-
runList('packages', oldToc[4]);
60+
61+
_.each(oldToc[4][0], id => {
62+
var name = id.name || id;
63+
idsToPagesWithNoHash[name] = 'packages/' + name + '.html';
64+
});
4665

4766
_.each(oldToc[6][0], id => {
4867
idsToPages[id.replace(/\s|\-|\//g, '')] = 'commandline.html';
4968
});
5069

51-
console.log(JSON.stringify(idsToPages, null, 2));
70+
_.each(_.union(_.keys(idsToPages), _.keys(idsToPagesWithNoHash)), id => {
71+
if (idsToPages[id]) {
72+
var page = idsToPages[id];
73+
var name = idToName[id] || id;
74+
var nameId = name.replace(/[.#]/g, "-");
75+
console.log(` full/${id}: '${page}#${nameId}'`);
76+
} else {
77+
var page = idsToPagesWithNoHash[id];
78+
console.log(` full/${id}: '${page}'`);
79+
}
80+
});

conversion/old-toc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ module.exports = [
305305
{name: "Assets.getBinary", id: "assets_getBinary"}
306306
],
307307

308-
{name: "package.js", id: "packagejs"}, [
308+
"packagejs", [
309309
{name: "Package.describe", id: "packagedescription"},
310310
{name: "Package.onUse", id: "packagedefinition"}, [
311311
{name: "api.versionsFrom", id: "pack_versions"},
@@ -324,7 +324,7 @@ module.exports = [
324324
]
325325
],
326326

327-
{name: "mobile-config.js", id: "mobileconfigjs"}, [
327+
"mobile-config", [
328328
{name: "App.info", id: "App-info"},
329329
{name: "App.setPreference", id: "App-setPreference"},
330330
{name: "App.accessRule", id: "App-accessRule"},

scripts/api-box.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ hexo.extend.tag.register('apibox', function(args) {
3030
};
3131
var data = _.extend({}, defaults, options, apiData({ name: name }));
3232

33-
if (nameToId[data.longname]) {
34-
data.id = nameToId[data.longname];
35-
} else {
36-
// fallback
37-
data.id = data.longname.replace(/[.#]/g, "-");
38-
}
33+
data.id = data.longname.replace(/[.#]/g, "-");
3934

4035
data.signature = signature(data, { short: false});
4136
data.title = signature(data, {

scripts/follow-redirects.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/old-redirects.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// These are the redirects that were previously setup for the docs
2-
3-
module.exports = function() {
2+
var oldRedirects = function() {
43
// make links backwards compatible - for example, #deps -> #tracker
54

65
// Links from the old basic API into the closest full-api section
@@ -145,3 +144,10 @@ module.exports = function() {
145144
window.location = "#" + redirect;
146145
}
147146
}
147+
148+
hexo.extend.tag.register('oldRedirects', function(args) {
149+
return '<script>\n' +
150+
'var oldRedirects = ' + oldRedirects + ';\n' +
151+
'oldRedirects();\n' +
152+
'</script>';
153+
});

scripts/redirects.js

Lines changed: 0 additions & 255 deletions
This file was deleted.

0 commit comments

Comments
 (0)