Skip to content

Commit

Permalink
remove website/.docusaurus and clean up scripts (finos#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi authored Mar 14, 2023
1 parent bc34208 commit c9c9993
Show file tree
Hide file tree
Showing 64 changed files with 127 additions and 7,269 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/docusaurus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ jobs:
else echo "Skipping patching, as this is the finos user on github"
fi
- name: Build Website
working-directory: ./website
run: |
./scripts/build-site.sh
yarn install
yarn build
- name: Search for Broken Links
run: |
node ./scripts/check-legend-application-documentation-broken-links.js
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ lib/core/MetadataBlog.js
website/translated_docs
website/build/
website/node_modules
website/i18n/*
website/i18n/
website/package-lock.json
website/.docusaurus
website/.docusaurus/*
website/.docusaurus/

# Ignore auto generated contribute.md and roadmap.md file
docs/contribute.md
Expand Down
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ You can get involved with Legend by suggesting topics you'd like to see in our d

To make edits to the website itself, you need to run the website locally. You must have:

- A Git client installed to checkout the code from github.com/finos/legend (`master` branch). The `git` command must be available via command-line, as it's needed to run the `build-site.sh` script.
- A Git client installed to checkout the code from github.com/finos/legend (`master` branch). The `git` command must be available via command-line.
- [Yarn installed](https://yarnpkg.com/lang/en/docs/install).

The following code automatically launches a browser and takes you to the staging website, located at http://localhost:3000. File changes are live rendered, speeding up the editorial workflow.

```git
```sh
git clone git@github.com:<yourfork>/legend.git
git checkout -b feature/myProposedDocChanges
cd legend ; ./scripts/build-site.sh
cd website ; yarn start
cd legend/website
yarn start
```

Once you're satisfied with your documentation changes, commit and propose them in line with the general process described above. Specifically for doc edits, it might look like this:
Expand All @@ -124,9 +124,6 @@ To learn more about Docusaurus, read the following resources:
- https://finosfoundation.atlassian.net/wiki/spaces/FDX/pages/844759075/Using+Docusaurus+recommended
- https://docusaurus.io

**Note:** [The documentation build script](https://github.com/finos/legend/blob/master/scripts/build-site.sh) can be configured to pull in and include files from GitLab repositories housing modeling documentation into the GitHub pages/Docusaurus-powered site.


## 4. Contribute issues: identify bugs, suggest new features, and provide feedback on prioritization
View the prerequisites and steps to report an issue in GitHub.

Expand Down
63 changes: 0 additions & 63 deletions scripts/build-site.sh

This file was deleted.

179 changes: 118 additions & 61 deletions scripts/check-legend-application-documentation-broken-links.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,138 @@
const fs = require("fs");
const http = require("http");
const https = require("https");
const path = require("path");
const { parse } = require("url");

const DOC_WEBSITE_URL = "https://legend.finos.org/";
const APPLICATION_DOC_DIRECTORY =
"website/static/resource/studio/documentation/";
const WEBSITE_CONTENT_DIRECTORY = "./website/build/";
const APPLICATION_DOC_DIRECTORY = path.resolve(
__dirname,
"../website/static/resource/studio/documentation/"
);
const WEBSITE_CONTENT_DIRECTORY = path.resolve(__dirname, "../website/build/");

var files = fs.readdirSync(APPLICATION_DOC_DIRECTORY);
var brokenUrls = [];
async function detectBrokenLinks() {
const files = fs.readdirSync(APPLICATION_DOC_DIRECTORY);

for (let i = 0; i < files.length; i++) {
if (!files[i].endsWith(".json")) continue;
var jsonObject = JSON.parse(
fs.readFileSync(APPLICATION_DOC_DIRECTORY + files[i], "utf8")
);
const brokenLinks = (
await Promise.all(
files.flatMap((file) => {
const fileContent = JSON.parse(
fs.readFileSync(path.resolve(APPLICATION_DOC_DIRECTORY, file), "utf8")
);

const keys = Object.keys(jsonObject.entries);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (jsonObject.entries[key].url == undefined) {
continue;
}
lookForUrl(jsonObject.entries[key].url);
}
}
return Object.values(fileContent.entries)
.filter((entry) => entry.url)
.map((entry) => checkLink(entry.url));
})
)
).filter(Boolean);

if (brokenUrls.length !== 0) {
throw new Error("Broken link(s) found: " + brokenUrls);
if (brokenLinks.length !== 0) {
throw new Error(
`Found ${brokenLinks.length} broken link(s):\n${brokenLinks.join("\n")}`
);
} else {
console.log(`No broken links found!`);
}
}

async function lookForUrlWithAnchor(url) {
const locationOfFile = url
.substring(0, url.lastIndexOf("/"))
.replace(DOC_WEBSITE_URL, "");

const filePathName =
WEBSITE_CONTENT_DIRECTORY +
locationOfFile +
url.substring(url.lastIndexOf("/"), url.lastIndexOf("#")) +
".html";

const anchorTag = url.substring(url.lastIndexOf("#"));

if (await fs.existsSync(filePathName)) {
await fs.readFile(filePathName, "UTF-8", (err, data) => {
if (!data) {
collectionOfErrors.push(["\n" + filePathName + "\n"]);
// Use `HEAD` request via http to check if the url still exists
// See https://stackoverflow.com/questions/60841965/how-can-i-check-to-see-if-a-url-exists-or-not
// See https://github.com/nwaughachukwuma/url-exists-nodejs
async function checkExternalLinkExists(url) {
return new Promise((resolve) => {
const req = http.request(
{
method: "HEAD",
host: parse(url).host,
path: parse(url).pathname,
port: 80,
},
(response) => {
// NOTE: only 400 requests are considered not found
resolve(response.statusCode < 400 || response.statusCode >= 500);
}
);

if (!data.toLocaleLowerCase().includes(anchorTag)) {
brokenUrls.push(["\n" + url + "\n"]);
throw new Error("Broken link(s) found: " + brokenUrls);
}
});
} else {
brokenUrls.push(["\n" + url + "\n"]);
}
req.end();
});
}

async function lookForUrl(url) {
currUrl = url.replace(DOC_WEBSITE_URL, "");
lastDirectoryIndex = currUrl.lastIndexOf("/");
async function fetchExternalLinkSiteData(url) {
return new Promise((resolve, reject) => {
https.get(url, (response) => {
let chunks_of_data = [];
response.on("data", (fragments) => {
chunks_of_data.push(fragments);
});
response.on("end", () => {
let response_body = Buffer.concat(chunks_of_data);
resolve(response_body.toString());
});
response.on("error", (error) => {
reject(error);
});
});
});
}

fileName = currUrl.substring(lastDirectoryIndex);
currUrlFinal = currUrl.substring(0, lastDirectoryIndex);
async function checkLink(url) {
if (!url.startsWith(DOC_WEBSITE_URL)) {
// we will not handle unsecured links
if (!url.startsWith("https://")) {
return undefined;
}

if (fs.existsSync(WEBSITE_CONTENT_DIRECTORY + currUrlFinal)) {
if (fileName.lastIndexOf("#") !== -1) {
//includes markdown tag
lookForUrlWithAnchor(url);
let result = undefined;
const urlExists = await checkExternalLinkExists(url);
if (urlExists) {
await fetchExternalLinkSiteData(url)
.then((data) => {
if (
url.lastIndexOf("#") !== -1 &&
!data.includes(url.substring(url.lastIndexOf("#")))
) {
result = url;
}
})
.catch(() => {
result = url;
});
} else {
if (!fs.existsSync(currUrlFinal + fileName + ".md")) {
brokenUrls.push(["\n" + url + "\n"]);
}
result = url;
}
} else {
brokenUrls.push(["\n" + url + "\n"]);
return result;
}

return;
const relativeUrl = url.substring(DOC_WEBSITE_URL.length);
const anchorIdx = relativeUrl.lastIndexOf("#");
const anchorTag =
anchorIdx !== -1 ? relativeUrl.substring(anchorIdx) : undefined;
const filePath =
anchorIdx !== -1
? path.resolve(
WEBSITE_CONTENT_DIRECTORY,
`${relativeUrl.substring(0, anchorIdx)}.html`
)
: path.resolve(WEBSITE_CONTENT_DIRECTORY, `${relativeUrl}.html`);

if (fs.existsSync(filePath)) {
if (anchorTag) {
try {
const data = fs.readFileSync(filePath, {
encoding: "utf-8",
});
if (data && !data.toLocaleLowerCase().includes(anchorTag)) {
return url;
}
} catch {
return url;
}
}
return undefined;
}
return url;
}

detectBrokenLinks();
5 changes: 0 additions & 5 deletions website/.docusaurus/DONT-EDIT-THIS-FOLDER

This file was deleted.

Loading

0 comments on commit c9c9993

Please sign in to comment.