Skip to content

Commit ac94c5f

Browse files
committed
#120 test update switch for relative links
1 parent 069ffa9 commit ac94c5f

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

.github/workflows/link_check.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,31 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v4
1313

14-
- name: Set up R # Install R from CRAN
14+
- name: Set up R
1515
uses: r-lib/actions/setup-r@v2
1616
with:
17-
r-version: '4.4.3' # You can specify a different R version if needed
17+
r-version: '4.4.3'
1818

1919
- name: Install R packages
2020
run: |
2121
Rscript -e 'install.packages("fs")'
2222
shell: bash
2323

24-
- name: Switch .qmd to .md
24+
- name: Switch .qmd to .md and Update Links
2525
run: Rscript R/switch.R
2626
shell: bash
2727

28+
- name: Verify .qmd Conversion
29+
run: |
30+
if ls **/*.qmd; then
31+
echo "Error: .qmd files still exist after switch.R!"
32+
exit 1
33+
fi
34+
echo "All .qmd files successfully converted to .md."
35+
2836
- name: Link Checker
2937
uses: lycheeverse/lychee-action@v1.8.0
3038
with:
3139
fail: true
32-
exclude-paths: "**/*.qmd"
3340
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

R/switch.R

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
1-
#' fixes link-check problem
2-
#' Finds whether any files use the string: "(.mailto:" for linking email adresses
3-
#' then just replaces with: "(mailto:" as is markdown standard
1+
#' Fixes link-check problem
2+
#' - Finds files that use the string "(.mailto:" and corrects to "(mailto:"
3+
#' - Updates links to `.qmd` files to point to `.md` files.
44
#'
55
#' @param file_list vector of filenames
66
#'
7-
#' @return messages only. side effect is: changes files.
7+
#' @return messages. Side effect: modifies files.
88
modify_files <- function(file_list) {
9-
# Create an empty vector to store the file names that contain the string
9+
# Create an empty vector to store file names that need modifications
1010
matching_files <- c()
1111

12-
# Iterate over each file in the directory
12+
# Iterate over each file to check for issues
1313
for (file in file_list) {
1414
# Read the contents of the file
1515
file_contents <- readLines(file)
1616

17-
# Check if the file contains the string "(.mailto:"
18-
if (any(grepl("\\(\\.mailto:", file_contents))) {
17+
# Check if the file contains the string "(.mailto:" OR references to `.qmd` files
18+
if (any(grepl("\\(\\.mailto:", file_contents)) || any(grepl("\\.qmd\\)", file_contents))) {
1919
# Add the file name to the vector
2020
matching_files <- c(matching_files, file)
2121
}
2222
}
2323

24-
# Iterate over the matching files
24+
# Iterate over the matching files to apply fixes
2525
for (file in matching_files) {
2626
# Read the contents of the file
2727
file_contents <- readLines(file)
2828

29-
# Remove the "." from each line that contains the string
29+
# Fix email links
3030
modified_contents <- gsub("\\(\\.mailto:", "(mailto:", file_contents)
3131

32+
# Update links to `.qmd` files to point to `.md` files
33+
# Matches patterns like `[text](filename.qmd)` and replaces `.qmd` with `.md`
34+
modified_contents <- gsub("\\.qmd\\)", ".md)", modified_contents)
35+
3236
# Write the modified contents back to the file
3337
writeLines(modified_contents, file)
3438

35-
# Print a message indicating the modification has been made
39+
# Print a message indicating what modifications have been made
3640
message("Modified file:", file, "\n")
3741
}
3842

39-
# Print the list of matching files
43+
# Print a list of matching files that were modified
4044
message("Matching files:", matching_files, "\n")
4145
}
4246

43-
# get all qmd files
47+
# Get all `.qmd` files
4448
all_qmd <- list.files(full.names = FALSE, all.files = FALSE, pattern = ".qmd$", recursive = TRUE)
4549

46-
# modify if needed the link to email problem for link checker
50+
# Modify files to fix email links and update `.qmd` references
4751
modify_files(all_qmd)
48-
# get filenames ending with .md
52+
53+
# Generate a list of `.md` filenames that will replace `.qmd` files
4954
all_md <- gsub(".qmd$", ".md", all_qmd)
50-
# rename all files
51-
file.rename(all_qmd, all_md)
55+
56+
# Rename all `.qmd` files to `.md`
57+
file.rename(all_qmd, all_md)

0 commit comments

Comments
 (0)