Yay! Fixed. Also added some style changes

This commit is contained in:
ViViDboarder 2016-07-26 17:21:56 -07:00
parent 87db2342aa
commit e64ac5df22
6 changed files with 86 additions and 29 deletions

4
.gitignore vendored
View File

@ -5,3 +5,7 @@
*.html
Content/
docSet.dsidx
# Downloaded CSS files
docs.min.css
holygrail.min.css
syntax-highlighter.min.css

View File

@ -1,6 +1,6 @@
default: complete
complete: run-combined package-apex package-vf package-combined
complete: run-combined package-combined clean-index run-apex package-apex clean-index run-vf package-vf
run-apex:
(cd SFDashC && go run *.go --silent apexcode)
@ -15,8 +15,9 @@ package-apex:
$(eval type = Apex)
$(eval package = Salesforce $(type).docset)
mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/atlas.en-us.200.0.apexcode.meta "$(package)/Contents/Resources/Documents/"
cp -r SFDashC/atlas.en-us.apexcode.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(type).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/"
@ -24,8 +25,9 @@ package-vf:
$(eval type = Pages)
$(eval package = Salesforce $(type).docset)
mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/atlas.en-us.200.0.pages.meta "$(package)/Contents/Resources/Documents/"
cp -r SFDashC/atlas.en-us.pages.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(type).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/"
@ -35,10 +37,14 @@ package-combined:
mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/*.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(type).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/"
clean:
rm -fr SFDashC/*.meta
clean-index:
rm -f SFDashC/docSet.dsidx
clean: clean-index
rm -fr SFDashC/*.meta
rm -f SFDashC/*.css
rm -fr *.docset

View File

@ -12,5 +12,7 @@
<true/>
<key>dashIndexFilePath</key>
<string>apexcode.html</string>
<key>DashDocSetFallbackURL</key>
<string>https://developer.salesforce.com/docs/</string>
</dict>
</plist>

View File

@ -13,5 +13,7 @@
<true/>
<key>dashIndexFilePath</key>
<string>index.htm</string>
<key>DashDocSetFallbackURL</key>
<string>https://developer.salesforce.com/docs/</string>
</dict>
</plist>

View File

@ -12,5 +12,7 @@
<true/>
<key>dashIndexFilePath</key>
<string>pages.html</string>
<key>DashDocSetFallbackURL</key>
<string>https://developer.salesforce.com/docs/</string>
</dict>
</plist>

View File

@ -7,6 +7,7 @@ import (
"fmt"
"github.com/coopernurse/gorp"
_ "github.com/mattn/go-sqlite3"
"io"
"io/ioutil"
"net/http"
"os"
@ -24,7 +25,7 @@ TODO:
// CSS Paths
var cssBasePath = "https://developer.salesforce.com/resource/stylesheets"
var cssFiles = []string{"docs.min.css"}
var cssFiles = []string{"holygrail.min.css", "docs.min.css", "syntax-highlighter.min.css"}
// JSON Structs
@ -163,7 +164,10 @@ func saveMainContent(toc *AtlasTOC) {
ExitIfError(err)
defer ofile.Close()
_, err = ofile.WriteString(content)
_, err = ofile.WriteString(
"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />" +
content,
)
ExitIfError(err)
}
}
@ -174,6 +178,13 @@ func main() {
WithoutWarning()
}
// Download CSS
for _, cssFile := range cssFiles {
throttle <- 1
wg.Add(1)
go downloadCSS(cssFile, &wg)
}
// Init the Sqlite db
dbmap = initDb()
err := dbmap.TruncateTables()
@ -198,16 +209,6 @@ func main() {
printSuccess(toc)
}
// Download CSS
throttle <- 1
/*
* wg.Add(1)
* for _, cssUrl := range cssFiles {
* go downloadLink(cssBasePath+"/"+cssUrl, &wg)
* }
*/
wg.Wait()
}
@ -333,23 +334,25 @@ func (entry TOCEntry) CleanTitle(t SupportedType) string {
}
// GetRelLink extracts only the relative link from the Link Href
func (entry TOCEntry) GetRelLink() (relLink string) {
func (entry TOCEntry) GetRelLink(removeAnchor bool) (relLink string) {
if entry.LinkAttr.Href == "" {
return
}
// Get the JSON file
relLink = entry.LinkAttr.Href
anchorIndex := strings.LastIndex(relLink, "#")
if anchorIndex > 0 {
relLink = relLink[0:anchorIndex]
if removeAnchor {
anchorIndex := strings.LastIndex(relLink, "#")
if anchorIndex > 0 {
relLink = relLink[0:anchorIndex]
}
}
return
}
// GetContent retrieves Content for this TOCEntry from the API
func (entry TOCEntry) GetContent(toc *AtlasTOC) (content *TOCContent, err error) {
relLink := entry.GetRelLink()
relLink := entry.GetRelLink(true)
if relLink == "" {
return
}
@ -371,7 +374,6 @@ func (entry TOCEntry) GetContent(toc *AtlasTOC) (content *TOCContent, err error)
// Read the downloaded JSON
defer resp.Body.Close()
contents, err := ioutil.ReadAll(resp.Body)
// fmt.Println(string(contents))
if err != nil {
return
}
@ -379,6 +381,13 @@ func (entry TOCEntry) GetContent(toc *AtlasTOC) (content *TOCContent, err error)
// Load into Struct
content = new(TOCContent)
err = json.Unmarshal([]byte(contents), content)
if err != nil {
fmt.Println("Error reading JSON")
fmt.Println(resp.Status)
fmt.Println(url)
fmt.Println(string(contents))
return
}
return
}
@ -435,19 +444,19 @@ func processChildReferences(entry TOCEntry, entryType *SupportedType, toc *Atlas
}
// GetContentFilepath returns the filepath that should be used for the content
func (entry TOCEntry) GetContentFilepath(toc *AtlasTOC) string {
relLink := entry.GetRelLink()
func (entry TOCEntry) GetContentFilepath(toc *AtlasTOC, removeAnchor bool) string {
relLink := entry.GetRelLink(removeAnchor)
if relLink == "" {
ExitIfError(NewFormatedError("Link not found for %s", entry.ID))
}
return fmt.Sprintf("%s/%s/%s", toc.Version.VersionURL, toc.Deliverable, relLink)
return fmt.Sprintf("atlas.%s.%s.meta/%s/%s", toc.Locale, toc.Deliverable, toc.Deliverable, relLink)
}
func downloadContent(entry TOCEntry, toc *AtlasTOC, wg *sync.WaitGroup) {
defer wg.Done()
filePath := entry.GetContentFilepath(toc)
filePath := entry.GetContentFilepath(toc, true)
// Make sure file doesn't exist first
if _, err := os.Stat(filePath); os.IsNotExist(err) {
content, err := entry.GetContent(toc)
@ -461,13 +470,45 @@ func downloadContent(entry TOCEntry, toc *AtlasTOC, wg *sync.WaitGroup) {
ofile, err := os.Create(filePath)
ExitIfError(err)
header := "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />" +
"<base href=\"../../\"/>\n"
for _, cssFile := range cssFiles {
header += fmt.Sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">", cssFile)
}
header += "<style>body { padding: 15px; }</style>"
defer ofile.Close()
_, err = ofile.WriteString("<base href=\"../../\"/>\n" + content.Content)
_, err = ofile.WriteString(
header + content.Content,
)
ExitIfError(err)
}
<-throttle
}
func downloadCSS(fileName string, wg *sync.WaitGroup) {
defer wg.Done()
if _, err := os.Stat(fileName); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(fileName), 0755)
ExitIfError(err)
ofile, err := os.Create(fileName)
ExitIfError(err)
defer ofile.Close()
cssURL := cssBasePath + "/" + fileName
response, err := http.Get(cssURL)
ExitIfError(err)
defer response.Body.Close()
_, err = io.Copy(ofile, response.Body)
ExitIfError(err)
}
<-throttle
}
/**********************
Database
**********************/
@ -477,7 +518,7 @@ func saveSearchIndex(dbmap *gorp.DbMap, entry TOCEntry, entryType *SupportedType
return
}
relLink := entry.GetContentFilepath(toc)
relLink := entry.GetContentFilepath(toc, false)
name := entry.CleanTitle(*entryType)
if entryType.ShowNamespace && len(entryHierarchy) > 0 {
// Show namespace for methods