Skip to content

Commit

Permalink
URLTest Checks and Fixes Relative Links
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Jun 11, 2024
1 parent c4a05a4 commit 2c735e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/url_check_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup dotnet
uses: actions/setup-dotnet@v3
Expand All @@ -22,3 +23,17 @@ jobs:
cd "URL Test"
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 URLTest.csproj
dotnet run bin/Debug/net6.0/process.dll
continue-on-error: true

- name: Push to Branch
run: |-
if [[ $(git diff | wc -m) == 0 ]]; then
exit 0
fi
BRANCH=github-action-url-test
git config user.name GitHub Actions
git config user.email [email protected]
git checkout -b $BRANCH
git add .
git commit -m "Code generated by URLTest"
git push --set-upstream origin $BRANCH -f
21 changes: 16 additions & 5 deletions URL Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using QuantConnect;
using QuantConnect.Logging;
using QuantConnect.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -44,13 +45,13 @@ public class Program
const string path = "..";
const string root = "https://www.quantconnect.com/";
const string leanIo = "https://www.lean.io/";
const string strategyPhp = "../03 Writing Algorithms/42 Strategy Library/02 Tutorials.php";
static readonly string[] leanIoFolder = new string[] {"05 Lean CLI", "06 LEAN Engine"};
static readonly string[] ignoreFiles = new string[] {"../Resources/indicators/using-indicator.php"};
const string strategyPhp = $"{path}/03 Writing Algorithms/42 Strategy Library/02 Tutorials.php";
static readonly string[] leanIoFolder = new[] { "05 Lean CLI", "06 LEAN Engine" };
static readonly string[] ignoreFiles = new[] { $"{path}/Resources/indicators/using-indicator.php" };

static void Main()
{
var leanIoErrorUrls = new string[] {
var leanIoErrorUrls = new [] {
"/docs/v2/cloud-platform", "/docs/v2/local-platform", "/docs/v2/writing-algorithm",
"/docs/v2/research-environment"
};
Expand Down Expand Up @@ -237,8 +238,11 @@ private static Dictionary<string, List<string>> GetAllUrls()

foreach (var file in allFiles)
{
foreach (var line in File.ReadAllLines(file))
var hasRelativeLink = false;
var lines = File.ReadAllLines(file);
for (var i = 0; i < lines.Length; i++)
{
var line = lines[i];
var end = line.IndexOf("href");
if (end < 0 ) continue;
var start = line[..end].IndexOf("<a");
Expand All @@ -265,7 +269,10 @@ private static Dictionary<string, List<string>> GetAllUrls()
{
if (url[0] == '#')
{
var old_url = url;
url = pathToLink(file, 1) + url;
lines[i] = line = line.Replace(old_url, url.Replace(root, "/"));
hasRelativeLink = true;
}
else if (url.Contains("mailto:"))
{
Expand Down Expand Up @@ -305,6 +312,10 @@ private static Dictionary<string, List<string>> GetAllUrls()
}
}
}
if (hasRelativeLink)
{
File.WriteAllLines(file, lines);
}
}

foreach (var file in ignoreFiles)
Expand Down

0 comments on commit 2c735e9

Please sign in to comment.