cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblotsky <...@git.apache.org>
Subject [GitHub] cordova-docs pull request: CB-11127 Improving internal linking
Date Fri, 22 Apr 2016 18:36:13 GMT
Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-docs/pull/584#discussion_r60783856
  
    --- Diff: tools/bin/gen_pages_dict.js ---
    @@ -0,0 +1,120 @@
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//     http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +
    +"use strict";
    +
    +var fs       = require("fs");
    +var path     = require("path");
    +var yaml     = require("js-yaml");
    +var walk     = require("walk");
    +var glob     = require("glob");
    +var Q        = require("q");
    +var optimist = require("optimist");
    +
    +var util = require("./util");
    +
    +// constants
    +var LATEST_ALIAS_URI = "/latest/";
    +
    +// helpers
    +function pathToURI(filePath, rootPath) {
    +    return filePath
    +        .replace(new RegExp("^" + rootPath), "")
    +        .replace(new RegExp("\\.md$"), ".html");
    +}
    +
    +function pagesFromRedirects(redirects, languages) {
    +    var pages = {};
    +
    +    // add docs redirects
    +    if (typeof redirects.docs !== "undefined") {
    +        for (var redirectSource in redirects.docs) {
    +
    +            // add an entry for the redirect's source, once for each language
    +            for (var i = 0; i < languages.length; i++) {
    +                var language = languages[i];
    +                var pagePath = "/docs/" + language + "/" + redirectSource;
    +
    +                pages[pagePath] = true;
    +            }
    +        }
    +    }
    +
    +    return pages;
    +}
    +
    +function isInLatestDocs(uri, latestVersion) {
    +    return uri.indexOf("/" + latestVersion + "/") !== (-1);
    +}
    +
    +// main
    +function main () {
    +
    +    // get args
    +    var argv = optimist
    +        .usage("Usage: $0 [options]")
    +        .demand("languages").describe("languages", "comma-separated list of docs languages")
    +        .demand("latestVersion").describe("latestVersion", "the current latest docs version")
    +        .demand("siteRoot").describe("siteRoot", "the source ToC for the given directory")
    +        .string("redirectsFile").describe("redirectsFile", "file containing redirects
for the website").default("redirectsFile", null)
    +        .argv;
    +
    +    var siteRootPath      = argv.siteRoot;
    +    var redirectsFilePath = argv.redirectsFile;
    +    var latestVersion     = argv.latestVersion;
    +    var languages         = argv.languages.split(",");
    +
    +    // pages to return
    +    var pages = {};
    +
    +    // add pages for redirects if a redirects file was passed
    +    if (redirectsFilePath !== null) {
    +
    +        var redirectsString = fs.readFileSync(redirectsFilePath);
    +        var redirects       = yaml.load(redirectsString);
    +        var redirectsPages  = pagesFromRedirects(redirects, languages);
    +
    +        pages = redirectsPages;
    +    }
    +
    +    // add entries for all Markdown files in the site root
    +    var allMarkdownFiles = path.join(siteRootPath, "**/*.md");
    +    glob(allMarkdownFiles, function (error, filePaths) {
    +        for (var i = 0; i < filePaths.length; i++) {
    +            var filePath = filePaths[i];
    +            var fileURI  = pathToURI(filePath, siteRootPath);
    +
    +            // add the page
    +            pages[fileURI] = true;
    +
    +            // also add /latest/ version for pages in latest docs
    +            if (isInLatestDocs(fileURI, latestVersion)) {
    +                var latestURI = fileURI.replace("/" + latestVersion + "/", LATEST_ALIAS_URI);
    --- End diff --
    
    This replaces `/6.x/` with `/latest/`, so it accounts for the slashes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message