You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2022/02/24 07:08:01 UTC
[lucenenet] 02/03: Docs: Updated View Source link to use current version tag rather than master branch
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 11c10bd2338fe33b3ae2ae31d3838f4f077c2e3c
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Thu Feb 24 13:46:08 2022 +0700
Docs: Updated View Source link to use current version tag rather than master branch
---
.../LuceneTemplate/ManagedReference.extension.js | 6 +-
.../apidocs/Templates/LuceneTemplate/common.js | 245 +++++++++++++++++++++
websites/apidocs/docfx.global.json | 9 +-
websites/apidocs/docfx.global.subsite.json | 5 +-
websites/apidocs/docs.ps1 | 1 +
websites/apidocs/toc.yml | 6 +-
websites/apidocs/toc/toc.yml | 6 +-
7 files changed, 263 insertions(+), 15 deletions(-)
diff --git a/websites/apidocs/Templates/LuceneTemplate/ManagedReference.extension.js b/websites/apidocs/Templates/LuceneTemplate/ManagedReference.extension.js
index 03bb818..af52187 100644
--- a/websites/apidocs/Templates/LuceneTemplate/ManagedReference.extension.js
+++ b/websites/apidocs/Templates/LuceneTemplate/ManagedReference.extension.js
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -29,6 +29,10 @@ exports.preTransform = function (model) {
if (model && model._gitSource && model.source && model.source.remote && model.source.remote.repo) {
model.source.remote.repo = model._gitSource;
}
+
+ if (model && model._gitContribute && model._gitContribute.tag && model.source && model.source.remote) {
+ model.source.remote.tag = model._gitContribute.tag;
+ }
return model;
}
diff --git a/websites/apidocs/Templates/LuceneTemplate/common.js b/websites/apidocs/Templates/LuceneTemplate/common.js
new file mode 100644
index 0000000..d56c74f
--- /dev/null
+++ b/websites/apidocs/Templates/LuceneTemplate/common.js
@@ -0,0 +1,245 @@
+/*
+ * 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.
+ */
+
+// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
+exports.path = {};
+exports.path.getFileNameWithoutExtension = getFileNameWithoutExtension;
+exports.path.getDirectoryName = getDirectoryName;
+
+exports.getHtmlId = getHtmlId;
+
+exports.getViewSourceHref = getViewSourceHref;
+exports.getImproveTheDocHref = getImproveTheDocHref;
+exports.processSeeAlso = processSeeAlso;
+
+exports.isAbsolutePath = isAbsolutePath;
+exports.isRelativePath = isRelativePath;
+
+function getFileNameWithoutExtension(path) {
+ if (!path || path[path.length - 1] === '/' || path[path.length - 1] === '\\') return '';
+ var fileName = path.split('\\').pop().split('/').pop();
+ return fileName.slice(0, fileName.lastIndexOf('.'));
+}
+
+function getDirectoryName(path) {
+ if (!path) return '';
+ var index = path.lastIndexOf('/');
+ return path.slice(0, index + 1);
+}
+
+function getHtmlId(input) {
+ if (!input) return '';
+ return input.replace(/\W/g, '_');
+}
+
+// Note: the parameter `gitContribute` won't be used in this function
+function getViewSourceHref(item, gitContribute, gitUrlPattern) {
+ if (!item || !item.source || !item.source.remote) return '';
+ return getRemoteUrl(item.source.remote, item.source.startLine - '0' + 1, null, gitUrlPattern);
+}
+
+function getImproveTheDocHref(item, gitContribute, gitUrlPattern) {
+ if (!item) return '';
+ if (!item.documentation || !item.documentation.remote) {
+ // LUCENENET TODO: Set up Improve This Doc to edit the .cs file (the xml doc comments) rather than creating a new .md file
+ //if (item || item.source || item.source.remote) {
+ // return getRemoteUrl(item.source.remote, item.source.startLine - '0' + 1, gitContribute, gitUrlPattern);
+ //} else {
+ return getNewFileUrl(item, gitContribute, gitUrlPattern);
+ //}
+ } else {
+ return getRemoteUrl(item.documentation.remote, item.documentation.startLine + 1, gitContribute, gitUrlPattern);
+ }
+}
+
+function processSeeAlso(item) {
+ if (item.seealso) {
+ for (var key in item.seealso) {
+ addIsCref(item.seealso[key]);
+ }
+ }
+ item.seealso = item.seealso || null;
+}
+
+function isAbsolutePath(path) {
+ return /^(\w+:)?\/\//g.test(path);
+}
+
+function isRelativePath(path) {
+ if (!path) return false;
+ return !exports.isAbsolutePath(path);
+}
+
+var gitUrlPatternItems = {
+ 'github': {
+ // HTTPS form: https://github.com/{org}/{repo}.git
+ // SSH form: git@github.com:{org}/{repo}.git
+ // generate URL: https://github.com/{org}/{repo}/blob/{branch}/{path}
+ 'testRegex': /^(https?:\/\/)?(\S+\@)?(\S+\.)?github\.com(\/|:).*/i,
+ 'generateUrl': function (gitInfo) {
+ var url = normalizeGitUrlToHttps(gitInfo.repo);
+ url = getRepoWithoutGitExtension(url);
+ url += '/blob' + '/' + gitInfo.branch + '/' + gitInfo.path;
+ if (gitInfo.startLine && gitInfo.startLine > 0) {
+ url += '/#L' + gitInfo.startLine;
+ }
+ return url;
+ },
+ 'generateNewFileUrl': function (gitInfo, uid) {
+ var url = normalizeGitUrlToHttps(gitInfo.repo);
+ url = getRepoWithoutGitExtension(url);
+ url += '/new';
+ url += '/' + gitInfo.branch;
+ url += '/' + getOverrideFolder(gitInfo.apiSpecFolder);
+ url += '/new?filename=' + getHtmlId(uid) + '.md';
+ url += '&value=' + encodeURIComponent(getOverrideTemplate(uid));
+ return url;
+ }
+ },
+ 'vso': {
+ // HTTPS form: https://{user}.visualstudio.com/{org}/_git/{repo}
+ // SSH form: ssh://{user}@{user}.visualstudio.com:22/{org}/_git/{repo}
+ // generated URL under branch: https://{user}.visualstudio.com/{org}/_git/{repo}?path={path}&version=GB{branch}
+ // generated URL under detached HEAD: https://{user}.visualstudio.com/{org}/_git/{repo}?path={path}&version=GC{commit}
+ 'testRegex': /^(https?:\/\/)?(ssh:\/\/\S+\@)?(\S+\.)?visualstudio\.com(\/|:).*/i,
+ 'generateUrl': function (gitInfo) {
+ var url = normalizeGitUrlToHttps(gitInfo.repo);
+ var branchPrefix = /[0-9a-fA-F]{40}/.test(gitInfo.branch) ? 'GC' : 'GB';
+ url += '?path=' + gitInfo.path + '&version=' + branchPrefix + gitInfo.branch;
+ if (gitInfo.startLine && gitInfo.startLine > 0) {
+ url += '&line=' + gitInfo.startLine;
+ }
+ return url;
+ },
+ 'generateNewFileUrl': function (gitInfo, uid) {
+ return '';
+ }
+ }
+}
+
+function getRepoWithoutGitExtension(repo) {
+ if (repo.substr(-4) === '.git') {
+ repo = repo.substr(0, repo.length - 4);
+ }
+ return repo;
+}
+
+function normalizeGitUrlToHttps(repo) {
+ var pos = repo.indexOf('@');
+ if (pos == -1) return repo;
+ return 'https://' + repo.substr(pos + 1).replace(/:[0-9]+/g, '').replace(/:/g, '/');
+}
+
+function getNewFileUrl(item, gitContribute, gitUrlPattern) {
+ // do not support VSO for now
+ if (!item.source) {
+ return '';
+ }
+
+ var gitInfo = getGitInfo(gitContribute, item.source.remote);
+ if (!gitInfo.repo || !gitInfo.branch || !gitInfo.path) {
+ return '';
+ }
+
+ var patternName = getPatternName(gitInfo.repo, gitUrlPattern);
+ if (!patternName) return patternName;
+ return gitUrlPatternItems[patternName].generateNewFileUrl(gitInfo, item.uid);
+}
+
+function getRemoteUrl(remote, startLine, gitContribute, gitUrlPattern) {
+ var gitInfo = getGitInfo(gitContribute, remote);
+ if (!gitInfo.repo || !gitInfo.branch || !gitInfo.path) {
+ return '';
+ }
+
+ var patternName = getPatternName(gitInfo.repo, gitUrlPattern);
+ if (!patternName) return '';
+
+ gitInfo.startLine = startLine;
+ // LUCENENET specific - change view source link to show latest tag, not the docs branch
+ if (!gitContribute && gitInfo.tag) {
+ gitInfo.branch = gitInfo.tag;
+ }
+ return gitUrlPatternItems[patternName].generateUrl(gitInfo);
+}
+
+function getGitInfo(gitContribute, gitRemote) {
+ // apiSpecFolder defines the folder contains overwrite files for MRef, the default value is apiSpec
+ var defaultApiSpecFolder = 'apiSpec';
+
+ var result = {};
+ if (gitContribute && gitContribute.apiSpecFolder) {
+ result.apiSpecFolder = gitContribute.apiSpecFolder;
+ } else {
+ result.apiSpecFolder = defaultApiSpecFolder;
+ }
+ mergeKey(gitContribute, gitRemote, result, 'repo');
+ mergeKey(gitContribute, gitRemote, result, 'branch');
+ mergeKey(gitContribute, gitRemote, result, 'path');
+ mergeKey(gitContribute, gitRemote, result, 'tag'); // LUCENENET specific
+
+ return result;
+
+ function mergeKey(source, sourceFallback, dest, key) {
+ if (source && source.hasOwnProperty(key)) {
+ dest[key] = source[key];
+ } else if (sourceFallback && sourceFallback.hasOwnProperty(key)) {
+ dest[key] = sourceFallback[key];
+ }
+ }
+}
+
+function getPatternName(repo, gitUrlPattern) {
+ if (gitUrlPattern && gitUrlPattern.toLowerCase() in gitUrlPatternItems) {
+ return gitUrlPattern.toLowerCase();
+ } else {
+ for (var p in gitUrlPatternItems) {
+ if (gitUrlPatternItems[p].testRegex.test(repo)) {
+ return p;
+ }
+ }
+ }
+ return '';
+}
+
+function getOverrideFolder(path) {
+ if (!path) return "";
+ path = path.replace('\\', '/');
+ if (path.charAt(path.length - 1) == '/') path = path.substring(0, path.length - 1);
+ return path;
+}
+
+function getOverrideTemplate(uid) {
+ if (!uid) return "";
+ var content = "";
+ content += "---\n";
+ content += "uid: " + uid + "\n";
+ content += "summary: '*You can override summary for the API here using *MARKDOWN* syntax'\n";
+ content += "---\n";
+ content += "\n";
+ content += "*Please type below more information about this API:*\n";
+ content += "\n";
+ return content;
+}
+
+function addIsCref(seealso) {
+ if (!seealso.linkType || seealso.linkType.toLowerCase() == "cref") {
+ seealso.isCref = true;
+ }
+}
diff --git a/websites/apidocs/docfx.global.json b/websites/apidocs/docfx.global.json
index 8e0f4fc..b46149e 100644
--- a/websites/apidocs/docfx.global.json
+++ b/websites/apidocs/docfx.global.json
@@ -1,14 +1,15 @@
{
- "_appTitle": "Apache Lucene.NET 4.8.0-beta00015 Documentation",
+ "_appTitle": "Apache Lucene.NET 4.8.0-beta00016 Documentation",
"_disableContribution": false,
"_appFaviconPath": "logo/favicon.ico",
"_enableSearch": true,
"_appLogoPath": "logo/lucene-net-color.png",
- "_appFooter": "Copyright \u0026copy; 2021 The Apache Software Foundation, Licensed under the \u003ca href=\u0027http://www.apache.org/licenses/LICENSE-2.0\u0027 target=\u0027_blank\u0027\u003eApache License, Version 2.0\u003c/a\u003e\u003cbr/\u003e \u003csmall\u003eApache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation. \u003cbr/\u003eAll other marks mentioned may be trademarks or regist [...]
+ "_appFooter": "Copyright \u0026copy; 2022 The Apache Software Foundation, Licensed under the \u003ca href=\u0027http://www.apache.org/licenses/LICENSE-2.0\u0027 target=\u0027_blank\u0027\u003eApache License, Version 2.0\u003c/a\u003e\u003cbr/\u003e \u003csmall\u003eApache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation. \u003cbr/\u003eAll other marks mentioned may be trademarks or regist [...]
"_gitContribute": {
"repo": "https://github.com/apache/lucenenet",
- "branch": "docs/4.8.0-beta00015",
- "apiSpecFolder": "websites/apidocs/apiSpec"
+ "branch": "docs/4.8.0-beta00016",
+ "apiSpecFolder": "websites/apidocs/apiSpec",
+ "tag": "Lucene.Net_4_8_0_beta00016"
},
"_gitSource": "https://github.com/apache/lucenenet.git"
}
diff --git a/websites/apidocs/docfx.global.subsite.json b/websites/apidocs/docfx.global.subsite.json
index b5a4166..6cf6b98 100644
--- a/websites/apidocs/docfx.global.subsite.json
+++ b/websites/apidocs/docfx.global.subsite.json
@@ -1,5 +1,4 @@
-{
+{
"_rel": "https://lucenenet.apache.org/docs/4.8.0-beta00009/",
- "_api": "https://lucenenet.apache.org/docs/4.8.0-beta00015/"
+ "_api": "https://lucenenet.apache.org/docs/4.8.0-beta00016/"
}
-
diff --git a/websites/apidocs/docs.ps1 b/websites/apidocs/docs.ps1
index 09044fa..38728b5 100644
--- a/websites/apidocs/docs.ps1
+++ b/websites/apidocs/docs.ps1
@@ -125,6 +125,7 @@ $DocFxJsonContent = Get-Content $DocFxGlobalJson | ConvertFrom-Json
$DocFxJsonContent._appFooter = "Copyright © $((Get-Date).Year) The Apache Software Foundation, Licensed under the <a href='http://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache License, Version 2.0</a><br/> <small>Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation. <br/>All other marks mentioned may be trademarks or registered trademarks of their respective owners.</small>"
$DocFxJsonContent._appTitle = "Apache Lucene.NET $LuceneNetVersion Documentation"
$DocFxJsonContent._gitContribute.branch = "docs/$LuceneNetVersion"
+$DocFxJsonContent._gitContribute.tag = "$VCSLabel"
$DocFxJsonContent | ConvertTo-Json -depth 100 | Set-Content $DocFxGlobalJson
# NOTE: The order of these depends on if one of the projects requries the xref map of another, normally all require the core xref map
diff --git a/websites/apidocs/toc.yml b/websites/apidocs/toc.yml
index 72dbfa1..446bef5 100644
--- a/websites/apidocs/toc.yml
+++ b/websites/apidocs/toc.yml
@@ -1,9 +1,7 @@
-- name: Lucene.Net API
- topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00015/
+- name: Lucene.Net API
+ topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00016/
- name: Lucene.Net CLI
href: ../../src/dotnet/tools/lucene-cli/docs/
topicHref: ../../src/dotnet/tools/lucene-cli/docs/index.md
- name: Lucene.Net Website
href: https://lucenenet.apache.org/
-
-
diff --git a/websites/apidocs/toc/toc.yml b/websites/apidocs/toc/toc.yml
index eab677c..f4c7b8d 100644
--- a/websites/apidocs/toc/toc.yml
+++ b/websites/apidocs/toc/toc.yml
@@ -1,6 +1,6 @@
-- name: Lucene.Net API
- topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00015
+- name: Lucene.Net API
+ topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00016
- name: Lucene.Net CLI
- topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00015/cli/index.html
+ topicHref: https://lucenenet.apache.org/docs/4.8.0-beta00016/cli/index.html
- name: Lucene.Net Website
topicHref: https://lucenenet.apache.org/