11import gitUrlParse from 'git-url-parse' ;
22import * as utils from './utilities.client' ;
3+ import { GIT_MAIN_BRANCH } from './consts' ;
34
45const regex = require ( './regexs' ) ;
56
@@ -67,10 +68,10 @@ export const customHeadingRenderer = (text, level, raw) => {
6768} ;
6869
6970/**
70- * @param {string } repoUrl
71+ * @param {string } gitRepoUrl
7172 */
72- export const parseRepoName = ( repoUrl ) => {
73- const parsedRepoUrl = gitUrlParse ( repoUrl ) ;
73+ export const parseRepoName = ( gitRepoUrl ) => {
74+ const parsedRepoUrl = gitUrlParse ( gitRepoUrl ) ;
7475 // Can't use parsedRepoUrl.full_name on it's own as Bitbucket adds irrelevant path suffix to the end of it
7576 const repoName = parsedRepoUrl . full_name . split ( '/' ) . slice ( 0 , 2 ) . join ( '/' ) ;
7677 return repoName ;
@@ -79,21 +80,21 @@ export const parseRepoName = (repoUrl) => {
7980/**
8081 * Generates URLs for RAW content such as images
8182 *
82- * @param {string } repoUrl
83+ * @param {string } gitRepoUrl
8384 * @param {string } gitBranchName
8485 */
85- export const generateRawGitRepoUrlPrefix = ( repoUrl , gitBranchName ) => {
86+ export const generateRawGitRepoUrlPrefix = ( gitRepoUrl , gitBranchName ) => {
8687 let urlPrefix ;
87- const repoFullName = parseRepoName ( repoUrl ) ;
88+ const repoFullName = parseRepoName ( gitRepoUrl ) ;
8889
8990 // Avoid errors created by missing branch name / badly formed URLs
90- const branchName = gitBranchName || 'main' ;
91+ const branchName = gitBranchName || GIT_MAIN_BRANCH ;
9192
92- if ( repoUrl . includes ( 'github.com' ) ) {
93+ if ( gitRepoUrl . includes ( 'github.com' ) ) {
9394 urlPrefix = `https://raw.githubusercontent.com/${ repoFullName } /${ branchName } ` ;
94- } else if ( repoUrl . includes ( 'gitlab.com' ) ) {
95+ } else if ( gitRepoUrl . includes ( 'gitlab.com' ) ) {
9596 urlPrefix = `https://gitlab.com/${ repoFullName } /-/raw/${ branchName } ` ;
96- } else if ( repoUrl . includes ( 'bitbucket.org' ) ) {
97+ } else if ( gitRepoUrl . includes ( 'bitbucket.org' ) ) {
9798 // Note: bytebucket is a raw content serving service by Bitbucket
9899 urlPrefix = `https://bytebucket.org/${ repoFullName } /raw/${ branchName } ` ;
99100 }
@@ -103,13 +104,13 @@ export const generateRawGitRepoUrlPrefix = (repoUrl, gitBranchName) => {
103104/**
104105 * Generates URLs for files and folders
105106 *
106- * @param {string } repoUrl
107+ * @param {string } gitRepoUrl
107108 * @param {string } gitBranchName
108109 * @param {string } href
109110 */
110- export const generateGitRepoUrlPrefix = ( repoUrl , gitBranchName , href ) => {
111+ export const generateGitRepoUrlPrefix = ( gitRepoUrl , gitBranchName , href ) => {
111112 let urlPrefix ;
112- const repoFullName = parseRepoName ( repoUrl ) ;
113+ const repoFullName = parseRepoName ( gitRepoUrl ) ;
113114
114115 const hrefParts = href . split ( '/' ) ;
115116 const lastHrefPart = hrefParts [ hrefParts . length - 1 ] ;
@@ -119,13 +120,13 @@ export const generateGitRepoUrlPrefix = (repoUrl, gitBranchName, href) => {
119120 const isTreeOrBlob = lastHrefPart . includes ( '.' ) ? 'blob' : 'tree' ;
120121
121122 // Avoid errors created by missing branch name / badly formed URLs
122- const branchName = gitBranchName || 'main' ;
123+ const branchName = gitBranchName || GIT_MAIN_BRANCH ;
123124
124- if ( repoUrl . includes ( 'github.com' ) ) {
125+ if ( gitRepoUrl . includes ( 'github.com' ) ) {
125126 urlPrefix = `https://github.com/${ repoFullName } /${ isTreeOrBlob } /${ branchName } ` ;
126- } else if ( repoUrl . includes ( 'gitlab.com' ) ) {
127+ } else if ( gitRepoUrl . includes ( 'gitlab.com' ) ) {
127128 urlPrefix = `https://gitlab.com/${ repoFullName } /-/${ isTreeOrBlob } /${ branchName } ` ;
128- } else if ( repoUrl . includes ( 'bitbucket.org' ) ) {
129+ } else if ( gitRepoUrl . includes ( 'bitbucket.org' ) ) {
129130 // Note: bytebucket is a raw content serving service by Bitbucket
130131 urlPrefix = `https://bitbucket.org/${ repoFullName } /src/${ branchName } ` ;
131132 }
@@ -141,11 +142,11 @@ export const generateGitRepoUrlPrefix = (repoUrl, gitBranchName, href) => {
141142 * 3) handle absolute links
142143 * @param {string } href
143144 * @param {string } text
144- * @param {string } repoUrl
145+ * @param {string } gitRepoUrl
145146 * @param {string } gitBranchName
146147 * @return {string }
147148*/
148- export const customLinkRenderer = ( href , text , repoUrl , gitBranchName ) => {
149+ export const customLinkRenderer = ( href , text , gitRepoUrl , gitBranchName ) => {
149150 // Handle anchor links, local Apify links, and mailto
150151 // Return Apify domain links without rel="nofollow" for SEO
151152 if ( href . startsWith ( '#' ) || href . includes ( 'apify.com' ) || regex . CONTACT_LINK_REGEX . test ( href ) ) {
@@ -154,8 +155,8 @@ export const customLinkRenderer = (href, text, repoUrl, gitBranchName) => {
154155 }
155156 // Only target relative URLs, which are used to refer to the git repo, and not anchors or absolute URLs
156157 const urlIsRelative = utils . isUrlRelative ( href ) ;
157- if ( urlIsRelative && repoUrl ) {
158- const urlPrefix = generateGitRepoUrlPrefix ( repoUrl , gitBranchName , href ) ;
158+ if ( urlIsRelative && gitRepoUrl ) {
159+ const urlPrefix = generateGitRepoUrlPrefix ( gitRepoUrl , gitBranchName , href ) ;
159160 // Since the README will always be in the root, the hrefs will have the same prefix, which needs to be taken off for the URL
160161 const cleanedHref = href . startsWith ( './' ) ? href . replace ( './' , '' ) : href ;
161162 href = `${ urlPrefix } /${ cleanedHref } ` ;
@@ -170,15 +171,15 @@ export const customLinkRenderer = (href, text, repoUrl, gitBranchName) => {
170171 * Parses the actor's repo URL to extract the repo name and owner name.
171172 * @param {string } href
172173 * @param {string } text
173- * @param {string } repoUrl
174+ * @param {string } gitRepoUrl
174175 * @param {string } gitBranchName
175176 * @return {string }
176177*/
177- export const customImageRenderer = ( href , text , repoUrl , gitBranchName ) => {
178+ export const customImageRenderer = ( href , text , gitRepoUrl , gitBranchName ) => {
178179 // Only target relative URLs, which are used to refer to the git repo, and not anchors or absolute URLs
179180 const urlIsRelative = utils . isUrlRelative ( href ) ;
180- if ( urlIsRelative && repoUrl ) {
181- const urlPrefix = generateRawGitRepoUrlPrefix ( repoUrl , gitBranchName ) ;
181+ if ( urlIsRelative && gitRepoUrl ) {
182+ const urlPrefix = generateRawGitRepoUrlPrefix ( gitRepoUrl , gitBranchName ) ;
182183 // Since the README will always be in the root, the hrefs will have the same prefix, which needs to be taken off for the URL
183184 const cleanedHref = href . startsWith ( './' ) ? href . replace ( './' , '' ) : href ;
184185 href = `${ urlPrefix } /${ cleanedHref } ` ;
0 commit comments