angular-cn/aio/tools/transforms/angular.io-package/index.js

62 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const Package = require('dgeni').Package;
const gitPackage = require('dgeni-packages/git');
const apiPackage = require('../angular-api-package');
const contentPackage = require('../angular-content-package');
const { extname, resolve } = require('canonical-path');
const { existsSync } = require('fs');
const { SRC_PATH } = require('../config');
module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPackage])
2017-04-01 02:01:44 -04:00
// This processor relies upon the versionInfo. See below...
.processor(require('./processors/processNavigationMap'))
.processor(require('./processors/createOverviewDump'))
.processor(require('./processors/cleanGeneratedFiles'))
// We don't include this in the angular-base package because the `versionInfo` stuff
// accesses the file system and git, which is slow.
.config(function(renderDocsProcessor, versionInfo) {
// Add the version data to the renderer, for use in things like github links
renderDocsProcessor.extraData.versionInfo = versionInfo;
})
.config(function(checkAnchorLinksProcessor, linkInlineTagDef, renderExamples) {
// Fail the processing if there is an invalid link
linkInlineTagDef.failOnBadLink = true;
checkAnchorLinksProcessor.$enabled = true;
// since we encode the HTML to JSON we need to ensure that this processor runs before that encoding happens.
checkAnchorLinksProcessor.$runBefore = ['convertToJsonProcessor'];
checkAnchorLinksProcessor.$runAfter = ['fixInternalDocumentLinks'];
// We only want to check docs that are going to be output as JSON docs.
checkAnchorLinksProcessor.checkDoc = (doc) => doc.path && doc.outputPath && extname(doc.outputPath) === '.json' && doc.docType !== 'json-doc';
// Since we have a `base[href="/"]` arrangement all links are relative to that and not relative to the source document's path
checkAnchorLinksProcessor.base = '/';
// Ignore links to local assets
// (This is not optimal in terms of performance without making changes to dgeni-packages there is no other way.
// That being said do this only add 500ms onto the ~30sec doc-gen run - so not a huge issue)
checkAnchorLinksProcessor.ignoredLinks.push({
test(url) {
return (existsSync(resolve(SRC_PATH, url)));
}
});
docs(aio): image sweep (#16609) * fix(aio): allow code blocks to clear floated images Previously the negative margin on the code headings were causing floated images to overlay the start of a code block. Now all code block successfully clear all floated elements. * feat(aio): add a `.clear` class for clearing floating images * fix(aio): tidy up image styles The css rules for `img.right` and `img.left` allow authors easy access to floating an image on the left or right, respectively. The `.image-display` rule which was always found on a figure has been simplified so that all figures have this styling. It is very unlikely that a figure will be used outside the content area; and at this time it seems like `figure` is as good an indicator that we want this kind of styling as anything. Now that images are all tagged with width and height values, we cannot assume to modify these dimensions via CSS as it can cause the image to lose its correct proportions. Until we find a better solition we must set `height` to `auto` when the screen width is below 1300px to ensure that these images maintain their proportions as they get shrunk to fit. * docs(aio): general tidy up of image HTML in guides Previously, the guides have a lot of inline image styling and unnecessary use of the `image-display` css class. Images over 700px are problematic for guide docs, so those have been given specific widths and associated heights. * docs(aio): use correct anchor for "back to the top" link The `#toc` anchor does not work when the page is wide enough that the TOC is floating to the side. * build(aio): add `#top-of-page` to path variants for link checking Since the `#top-of-page` is outside the rendered docs the `checkAnchorLinks` processor doesn't find them as valid targets for links. Adding them as a `pathVariant` solves this problem but will still catch links to docs that do not actually exist. * fix(aio): ensure that headings clear floated images * fix(aio): do not force live-example embedded image to 100% size This made them look too big, generally. Leaving them with no size means that they will look reasonable in large viewports and switch to 100% width in narrow viewports.
2017-05-09 18:53:32 -04:00
checkAnchorLinksProcessor.pathVariants = ['', '/', '.html', '/index.html', '#top-of-page'];
checkAnchorLinksProcessor.errorOnUnmatchedLinks = true;
// Make sure we fail if the examples are not right
renderExamples.ignoreBrokenExamples = false;
})
.config(function(renderLinkInfo, postProcessHtml) {
renderLinkInfo.docTypes = postProcessHtml.docTypes;
});