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 *.html
Content/ Content/
docSet.dsidx docSet.dsidx
# Downloaded CSS files
docs.min.css
holygrail.min.css
syntax-highlighter.min.css

View File

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

View File

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

View File

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

View File

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

View File

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