forked from google/WebFundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devsitePage.py
27 lines (25 loc) · 1.01 KB
/
devsitePage.py
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
import os
import logging
import devsiteParseMD
import devsiteParseHTML
SOURCE_PATH = os.path.join(os.path.dirname(__file__), 'src/content/')
def getPage(requestPath, lang):
fileLocations = [
os.path.join(SOURCE_PATH, lang, requestPath) + '.md',
os.path.join(SOURCE_PATH, lang, requestPath) + '.html',
os.path.join(SOURCE_PATH, lang, requestPath) + '.jshtml',
os.path.join(SOURCE_PATH, 'en', requestPath) + '.md',
os.path.join(SOURCE_PATH, 'en', requestPath) + '.html',
os.path.join(SOURCE_PATH, 'en', requestPath) + '.jshtml',
]
for fileLocation in fileLocations:
if os.path.isfile(fileLocation):
content = open(fileLocation, 'r').read()
content = content.decode('utf8')
if fileLocation.endswith('.jshtml'):
return content
if fileLocation.endswith('.md'):
return devsiteParseMD.parse(requestPath, fileLocation, content, lang)
if fileLocation.endswith('.html'):
return devsiteParseHTML.parse(requestPath, fileLocation, content, lang)
return None