forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.js
77 lines (74 loc) · 3.05 KB
/
patterns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// This module is intended to keep our use of regular expressions DRY,
// and to reduce the overhead of instantiating new RegExp objects
// if we're looking for part of a path, like /github,
// we allow for four characters after the string: (\/|$|\?|#)
// slash (/), end of line ($), query param (?), fragment (#)
// this will ensure we capture: /github/foo, /github, /github?query=foo, /github#foo
// and not capture: /github-foo
export const githubDotcom = /\/github(\/|$|\?|#)/
// we want to capture `/enterprise` and `/enterprise/foo` but NOT `/enterprise-admin`
export const enterprise = /\/enterprise(?:\/|$|\?)(\d+\.\d+)?/
export const admin = /enterprise\/(\d+\.\d+\/)?admin\/?/
export const gheUser = /enterprise\/(\d+\.\d+\/)?user(\/|$|\?)/
export const enterpriseHomepage = /\/enterprise\/?(\d+\.\d+)?$/
export const desktop = /desktop\//
export const oldGuidesPath = /(\/admin|(^|\/)desktop)\/guides/
// need to capture 11.10.340 and 2.0+
export const getEnterpriseVersionNumber = /^.*?enterprise\/(\d+\.\d+(?:\.340)?).*?$/
export const removeEnterpriseVersion = /(enterprise\/)\d+\.\d+\//
export const guides = /guides\//
export const hasLanguageCode = /^\/[a-z]{2}(\/|$|\?)/
export const getLanguageCode = /^\/([a-z]{2})/
export const trailingSlash = /^(.+?)\/+?$/
export const searchPath = /\/search(?:\/)?(\?)/
export const ymd = /^\d{4}-\d{2}-\d{2}$/
export const hasLiquid = /[{{][{%]/
export const dataReference = /{% ?data\s(?:early-access\.)?(?:reusables|variables|ui)\..*?%}/gm
export const imagePath = /\/?assets\/images\/.*?\.(png|svg|gif|pdf|ico|jpg|jpeg)/gi
export const homepagePath = /^\/\w{2}$/ // /en, /ja /cn
export const multipleSlashes = /^\/{2,}/
export const assetPaths = /\/(?:javascripts|stylesheets|assets|node_modules|dist)\//
export const oldApiPath = /\/v[34]\/(?!guides|overview).+?\/.+/
export const staticRedirect = /<link rel="canonical" href="(.+?)">/
export const enterpriseNoVersion = /\/enterprise\/([^\d].*$)/
// a {{ currentVersion }} in internal links may inject '<new-version@release>' into old paths,
// so the oldEnterprisePath regex must match: /enterprise/private-instances@latest/user,
// /enterprise/[email protected]/user, /enterprise/2.22/user, and /enterprise/user
export const oldEnterprisePath =
/\/([a-z]{2}\/)?(enterprise\/)?(\S+?@(\S+?\/))?(\d.\d+\/)?(user[/$])?/
// new versioning format patterns
export const adminProduct = /\/admin(\/|$|\?|#)/
export const insightsProduct = /\/insights(\/|$|\?|#)/
export const enterpriseServer = /\/enterprise-server@/
export const getEnterpriseServerNumber = /enterprise-server@(\d+\.\d+)/
export default {
githubDotcom,
enterprise,
admin,
gheUser,
enterpriseHomepage,
desktop,
oldGuidesPath,
getEnterpriseVersionNumber,
removeEnterpriseVersion,
guides,
hasLanguageCode,
getLanguageCode,
trailingSlash,
searchPath,
ymd,
hasLiquid,
dataReference,
imagePath,
homepagePath,
multipleSlashes,
assetPaths,
oldApiPath,
staticRedirect,
enterpriseNoVersion,
oldEnterprisePath,
adminProduct,
insightsProduct,
enterpriseServer,
getEnterpriseServerNumber,
}