Option Explicit
_____________________________________________________________________________________
Function PaleoFoodPath() As String
PaleoFoodPath = ReturnTopPath & "\paleofood.com"
If Not FileExists(PaleoFoodPath) Then
MsgBox "Cannot proceed. The website folder was not found:" & vbLf & PaleoFoodPath, vbCritical, "Aborted!"
End
End If
End Function
_____________________________________________________________________________________
Private Sub BuildPaleoSitemap()
' is button on Dashboard sheet
CreateSiteMapFromOtherSheet PaleoFoodPath
End Sub
_____________________________________________________________________________________
Private Sub EditChapters()
' is button on Dashboard sheet
' Columns: 0-recipe name, 1-credit
ExcelEditor PaleoFoodPath & "\site-building\Chapters.txt", Array(8.86, 40, 40, 20, 11.43, 50), Array("Chapter", "
tags", "Nav Title", "Topic", "Short Name", "Description")
AddSaveExitButtons 350, "SaveChapters", , "B"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SaveChapters()
' run from button on temp sheet
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\Chapters.txt", 2, 1, Range("A65536").End(xlUp).row, 6
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub EditGroups()
' Columns: 0-recipe name, 1-credit
ExcelEditor PaleoFoodPath & "\site-building\Groups.txt", Array(20, 20), Array("Chapter-Group", "Description")
AddSaveExitButtons 250, "SaveGroups"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SaveGroups()
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\Groups.txt", 2, 1, Range("A65536").End(xlUp).row, 2
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub EditSectionsInfo()
' Columns: 0-chapter-section code, 1-section title, 2-wiki link 1, 3-wiki link 2, 4-icon name, 5-icon alt, 6-icon title
' 7-icon name, 8-icon alt, 9-icon title, 10-cross reference
ExcelEditor PaleoFoodPath & "\site-building\Sections-Info.txt", Array(25, 30.43, 30, 20, 20, 20), Array("Chap-Sec Code", "Section", "Wiki Link 1", "Wiki Link 2", "Icon Name 1", "Icon Name 2")
AddSaveExitButtons 185, "SaveSectionsInfo"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SaveSectionsInfo()
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\Sections-Info.txt", 2, 1, Range("A65536").End(xlUp).row, 6
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub EditTableConts()
' Columns: 0-chapter, 1-major group, 2-section, 3-recipe name
ExcelEditor PaleoFoodPath & "\site-building\TableOfContents.txt", Array(8.86, 7, 18.57, 15.57, 81.57), Array("Chapter", "Group", "Section", "/ULs + toc's", "Recipe Name")
Columns("D").HorizontalAlignment = xlLeft
AddSaveExitButtons 360, "SaveTableConts"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SaveTableConts()
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\TableOfContents.txt", 2, 1, Range("A65536").End(xlUp).row, 5
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub EditThumbnailData()
ExcelEditor PaleoFoodPath & "\site-building\ThumbnailData.txt", Array(8, 12, 35, 60, 27, 19.57), Array("Chapter", "Section", "Thumbnail Name", "Web link", "Recipe Title", "Blog/Site")
AddSaveExitButtons 375, "SaveThumbnailData", , "D"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SaveThumbnailData()
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\ThumbnailData.txt", 2, 1, Range("A65536").End(xlUp).row, 6
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub EditPhotoCredits()
ExcelEditor PaleoFoodPath & "\site-building\PhotoCredits.txt", Array(31.86, 76.43), Array("Chapter - Recipe Name", "Credit")
AddSaveExitButtons 350, "SavePhotoCredits"
AddSortButtons 110, "SortCreditsA", 230, "SortCreditsB"
Application.Calculation = xlCalculationAutomatic
End Sub
_____________________________________________________________________________________
Private Sub SavePhotoCredits()
RemoveBlankRows
SaveAsPipeFile PaleoFoodPath & "\site-building\PhotoCredits.txt", 2, 1, Range("A65536").End(xlUp).row, 2
ExitDelimTable True
End Sub
_____________________________________________________________________________________
Private Sub SortCreditsA()
Columns("A:B").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes
End Sub
_____________________________________________________________________________________
Private Sub SortCreditsB()
Columns("A:B").Sort Key1:=Range("B2"), Key2:=Range("A2"), Order1:=xlAscending, Header:=xlYes
End Sub
_____________________________________________________________________________________
Private Sub ReduceRecipeName()
' button on Dashboard sheet
' turns recipe code into something usable for a file name (which should only be lowercase alphabetic, but dashes ok)
' then puts into Clipboard and clears from input cell
Dim i As Integer
Dim R As String, S As String, t As String
RestoreInputCells "fileify"
S = LCase(Range("fileify").Value)
S = Replace(S, " and ", "")
S = Replace(S, " stuffed ", "")
S = Replace(S, " with ", "")
S = Replace(S, " or ", "")
For i = 1 To Len(S)
t = Mid(S, i, 1)
If 0 < InStr("abcdefghijklmnopqrstuvwxyz", t) Then
R = R & t
End If
Next i
Range("fileify").Value = Replace(R, "recipe", "")
CopyToClipboard Range("fileify").Value
Range("fileify").ClearContents
End Sub
_____________________________________________________________________________________
Private Sub CheckForOpenAmpsInRecipes()
Dim j As Integer
Dim D As String, res As String, t As String
Dim Bad As Variant
D = RemoveHTML(ReadInFile(PaleoFoodPath & "\site-building\RecipeData.txt"))
Bad = Without(AllInStr(D, "&"), AllInStr(D, "&"))
If Not IsEmpty(Bad) Then
For j = 0 To UBound(Bad)
t = Left(DropStr(D, Bad(j)), 7)
If 0 = InStr(t, ";") Then
res = "&" & t & vbLf
End If
Next j
If res = "" Then GoTo Good
MsgBox "Open found:" & vbLf & vbLf & res, vbInformation, "Should Fix"
Else
Good:
MsgBox "All Good.", vbExclamation, "All Okay"
End If
End Sub
_____________________________________________________________________________________
Private Sub CheckPhotoCredits(Optional PhotoCredits As Variant)
' is button on Dashboard, also call by Process PaleoFood
Dim i As Integer
Dim res As String
If IsMissing(PhotoCredits) Then
PhotoCredits = ReadInDelimData(PaleoFoodPath & "\site-building\PhotoCredits.txt", "|")
End If
For i = 0 To UBound(PhotoCredits)
If Not FileExists(PaleoFoodPath & "\site-building\" & PhotoCredits(i, 0)) Then
res = res & ""
End If
Next i
If res <> "" Then
MsgBox "The following photo credits did not have pictures:" & res, vbExclamation, "Check for problems"
End If
End Sub
_____________________________________________________________________________________
Private Function WikiLink(ByVal WLink As String) As String
' turns WikiPedia link into code string
If WLink = "" Then Exit Function
Dim H As String
H = " "
End Function
_____________________________________________________________________________________
Private Function IconCode(ByRef TOCiconCode As Variant, ByVal Icode As String) As String
' turns icon image name into code string
' needs the code table passed to it/
If Icode = "" Then Exit Function
IconCode = ReturnMatrixCell(TOCiconCode, Icode, 0, 1)
End Function
_____________________________________________________________________________________
Private Function AddPicCredits(ByRef TableConts As Variant, PhotoCredits As Variant, i As Integer, PicLevel As Integer, PicStr As String) As Variant
' sub-function to ProcessPaleoFood
' reads, modifies and returns TableConts
' 6-piclevel, 7-picname, 8-picstr, 9-piccredit, 10-picalt, 11-width large pic, 12-height large pic
Dim f As String
Dim res As Variant
TableConts(i, 6) = PicLevel
TableConts(i, 7) = RemoveExtension(PicStr)
TableConts(i, 8) = PicStr
TableConts(i, 9) = ReturnMatrixCell(PhotoCredits, TableConts(i, 7), 0, 1)
If PicLevel = 1 Then
TableConts(i, 10) = "recipe picture"
ElseIf PicLevel = 2 Then
TableConts(i, 10) = "book cover image"
ElseIf PicLevel = 3 Then
TableConts(i, 10) = "section picture"
ElseIf PicLevel = 4 Then
TableConts(i, 10) = "chapter picture"
End If
' test if large picture exists and get its size
If Right(PicStr, 3) = "jpg" Then
f = PaleoFoodPath & "\pictures\" & TableConts(i, 7) & "-f.jpg"
If FileExists(f) Then
res = GetImageSize(f)
TableConts(i, 11) = res(0)
TableConts(i, 12) = res(1)
End If
End If
AddPicCredits = TableConts
End Function
_____________________________________________________________________________________
Private Sub ProcessPaleoFood()
' is button on Dashboard sheet
' processes all needed for web public
Dim NewFlag As Boolean, NotRecFlag As Boolean, RunSiteMap As Boolean
Dim Ctr As Integer, i As Integer, j As Integer, k As Integer, NotRecCount As Integer
Dim AmznTag As String, D As String, f As String, H As String, LastGrp As String
Dim LastSec As String, Link1 As String, Link2 As String
Dim PFDataPath As String, PicPath As String, RecipeDataStr As String, RecName As String
Dim RecPath As String, res As String, ShortName As String, t As String
Dim NextFN As String, NextFT As String, PrevFN As String, PrevFT As String
Dim AdUsage, AllThumbCode, AllTOC, AmzAds, Belows, Chapters, ChapTOC, DateAdded, DelStrings As Variant
Dim GroupTitles, HTOC, NoISBNs, PhotoCredits As Variant
Dim Recipes, RecNames, RPP, Sections, SecCodes, SecTemp, strts, SubHeads, TableConts As Variant
Dim TablDashNames, temp, ThumbData, ThumbTemp, TOCiconCode, TOCtemp As Variant
AmznTag = "paleofoodcom-20"
PFDataPath = PaleoFoodPath & "\site-building"
PicPath = PaleoFoodPath & "\pictures\"
RecPath = PaleoFoodPath & "\recipes\"
DoEvents
Application.StatusBar = "Getting data..."
' get chapter data:
' 0- filename (without file extension)
' 1- chapter tags
' 2- nav titles
' 3- topic
' 4- short name
' 5- description
Chapters = ReadInDelimData(PFDataPath & "\Chapters.txt", "|")
' recipes per page/chapter
ReDim RPP(UBound(Chapters))
' get section data:
' 0- chap-sec code
' 1- section title
' 2- Wiki link 1
' 3- Wiki link 2
' 4- icon name 1
' 5- icon name 2
Sections = ReadInDelimData(PFDataPath & "\Sections-info.txt", "|")
SecCodes = ReturnColumn(Sections, 0)
' check for duplicate section tags
If UBound(SecCodes) <> UBound(RemDupSameOrder(SecCodes)) Then
MsgBox "You have duplicate sections codes:" & vbLf & ReturnDups(SecCodes, True), vbCritical, "Aborted"
GoTo EndCode
End If
' we have a table of the recipe/section icons
TOCiconCode = ReadInDelimData(PFDataPath & "\TOCIconCode.txt", "|")
' check that Photo Credits have a picture. only a warning
PhotoCredits = ReadInDelimData(PFDataPath & "\PhotoCredits.txt", "|")
CheckPhotoCredits PhotoCredits
' get thumbnail data
' 0- chapter
' 1- section
' 3- thumbnail name
' 4- web link
' 5- recipe title
' 6- blog/site name
ThumbData = ReadInDelimData(PFDataPath & "\ThumbnailData.txt", "|")
' chapter sub-titles
SubHeads = ExtractData(PFDataPath & "\ChapSubTitles.txt", "*", 1)
' group titles. columns: 0- chapter-group, 1- title
GroupTitles = ReadInDelimData(PFDataPath & "\Groups.txt", "|")
' the section BELOW the table of contents
Belows = ExtractData(PFDataPath & "\BelowTables.txt", "*", 1)
' Amazon ads have a page/chapter index + the data file
AdUsage = ReadInDelimData(PFDataPath & "\AdUsage.txt", ",")
AmzAds = ExtractData(PFDataPath & "\AmazonAds.txt", "*", 1)
temp = ReturnColumn(AmzAds, 0)
If UBound(temp) <> UBound(RemDupSameOrder(temp)) Then
MsgBox "The AmazonAds.txt file has duplicates: " & ReturnDups(temp, True), vbCritical, "Aborted"
GoTo EndCode
End If
' recipe names and data
Application.StatusBar = "Retrieving Recipes..."
f = PFDataPath & "\RecipeData.txt"
RecNames = ExtractDataNames(f, , "~~~")
If UBound(RecNames) <> UBound(RemDupSameOrder(RecNames)) Then
MsgBox "The RecipeData.txt file has duplicate recipe names: " & ReturnDups(RecNames, True), vbCritical, "Aborted"
GoTo EndCode
End If
Recipes = ExtractData(f, "", 1, "~~~")
' get list of sections and edit for same name for section and recipe. they would clash in picture naming
temp = RemoveEmptiesInVector(Iota2V(RecNames, ReturnColumn(Sections, 0)))
If Not IsEmpty(temp) Then
MsgBox "Section and Recipe name clash:" & vbLf & Ravel(temp, vbLf), vbCritical, "Aborted"
GoTo EndCode
End If
' get table of contents: 0-chapter, 1-group, 2-section, 3-/ULs + toc-'s, 4-recipe name, add: 5-recipe title
Application.StatusBar = "Retrieving Table of Contents..."
TableConts = ReadInDelimData(PFDataPath & "\TableOfContents.txt", "|")
' remove non recipe entries
ReDim TablDashNames(UBound(TableConts))
For i = 0 To UBound(TableConts)
If 0 = InStr(TableConts(i, 4), " ") Then
TablDashNames(i) = TableConts(i, 0) & "-" & TableConts(i, 4)
End If
Next i
TablDashNames = RemoveEmptiesInVector(TablDashNames)
If UBound(TablDashNames) <> UBound(RemDupSameOrder(TablDashNames)) Then
MsgBox "The Table of Contents file has duplicate names: " & ReturnDups(TablDashNames, True), vbCritical, "Aborted"
GoTo EndCode
End If
' ~~~~ a bunch of data matching edits ~~~~
DoEvents
Application.StatusBar = "Checking source data..."
res = ""
If UBound(RecNames) <> UBound(TablDashNames) Then
res = res & "Number of recipes in the Table of Contents (" & (UBound(TablDashNames) + 1) & ") does not match Recipes (" & (UBound(RecNames) + 1) & ")." & vbLf
End If
For i = 0 To UBound(RecNames)
If Not IsMember(TablDashNames, RecNames(i)) Then
res = res & RecNames(i) & " in Recipes is not in the Table of Contents." & vbLf
End If
Next i
For i = 0 To UBound(TablDashNames)
If Not IsMember(RecNames, TablDashNames(i)) Then
res = res & TablDashNames(i) & " in Table of Contents is not in Recipes." & vbLf
End If
Next i
If res <> "" Then
CopyToClipboard res
MsgBox "Errors found:" & vbLf & vbLf & res & vbLf & vbLf & "The errors have been copied to the Clipboard. Paste someplace.", vbCritical, "Aborted"
GoTo EndCode
End If
' ~~~~ see if recipe is new, and not in DateAdded.txt ~~~~
f = PFDataPath & "\DateAdded.txt"
D = ReadInFile(f)
temp = ReturnColumn(ReadInDelimData(f, "|"), 0)
For i = 0 To UBound(RecNames)
If Not IsMember(temp, RecNames(i)) Then
D = D & RecNames(i) & "|" & Format(Now, "yyyymmdd") & vbCrLf
RunSiteMap = True
End If
Next i
SaveIfChanged f, D
' we need the list to see if recipe is recent
DateAdded = ReadInDelimData(f, "|")
' ~~~ put Recipes in TOC sort and save
DoEvents
Application.StatusBar = "Sorting Recipes..."
Recipes = IndexIntoVector(Recipes, Iota2V(RecNames, TablDashNames))
RecNames = TablDashNames
H = ""
For i = 0 To UBound(Recipes)
H = H & "~~~ " & TablDashNames(i) & vbCrLf & vbCrLf & Recipes(i) & vbCrLf
Next i
SaveIfChanged PFDataPath & "\RecipeData.txt", H
' ~~~ add recipe names to our table of contents
TableConts = AddColumns(TableConts, 1)
For i = 0 To UBound(TableConts)
If TableConts(i, 4) <> "" And InStr(TableConts(i, 4), " ") = 0 Then
j = Iota2(RecNames, TableConts(i, 0) & "-" & TableConts(i, 4))
H = Recipes(j)
TableConts(i, 5) = Left(H, InStr(H, vbCrLf) - 1)
' put recipe back into array w/o title (simply drops first 2 lines) and html adapted
H = DropStr(H, InStr(H, vbCrLf) + 1)
H = DropStr(H, InStr(H, vbCrLf) + 1)
Recipes(j) = TextToHtml(H)
End If
Next i
' ~~~~~~~~~~~~~~~~~~~ build Table of Contents for each chapter ~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Creating Tables of Contents..."
' we build two: chapter pages, and all on one page
ReDim HTOC(UBound(Chapters))
ReDim AllTOC(UBound(Chapters))
temp = Empty
For k = 0 To UBound(Chapters)
TOCtemp = CompressRows(TableConts, Chapters(k, 0))
Ctr = 1
TOCStart:
LastGrp = ""
LastSec = ""
H = ""
If Ctr = 1 Then
' we need table at the top, when many major groups in the chapter. see count test in code
If TOCtemp(0, 1) <> "" Then
temp = RemDupSameOrder(ReturnColumn(TOCtemp, 1))
If UBound(temp) > 4 Then
H = H & "
" & vbCrLf
H = H & "
Jump to:" & vbCrLf & vbCrLf
For j = 0 To UBound(temp)
t = ReturnMatrixCell(GroupTitles, Chapters(k, 0) & "-" & temp(j), 0, 1)
H = H & " • " & t & "" & vbCrLf
Next j
H = H & "
" & vbCrLf & vbCrLf
End If
End If
Else
' this is the chapter breaks when we are collecting for all on a page
H = H & "
" & Chapters(k, 2) & "
" & vbCrLf & vbCrLf
End If
' when no groups the entire page is an unordered list
If TOCtemp(0, 1) = "" Then
H = H & "
" & vbCrLf
End If
' ~~ loop for data rows in chapter data
DelStrings = Empty
For i = 0 To UBound(TOCtemp)
' do we have a group start?
If LastGrp <> TOCtemp(i, 1) And TOCtemp(i, 1) <> "" Then
LastGrp = TOCtemp(i, 1)
' title
t = ReturnMatrixCell(GroupTitles, Chapters(k, 0) & "-" & TOCtemp(i, 1), 0, 1)
If t <> "" Then
H = H & "
— " & t & " —
" & vbCrLf
End If
' open unordered list for recipes
H = H & vbCrLf & "
" & vbCrLf
End If
' ~~~ do we have a section start?
If LastSec <> TOCtemp(i, 2) And TOCtemp(i, 2) <> "" Then
LastSec = TOCtemp(i, 2)
' get row of section's info:
' 0- chap-sec code, 1- section title, 2- Wiki link 1, 3- Wiki link 2, 4-icon name 1, 5-icon name 2
SecTemp = CompressRows(Sections, TOCtemp(i, 0) & "-" & TOCtemp(i, 2))
' build section heading
H = H & "
"
' we save these links so we can remove them later for the all table of contents on one page
Link1 = "" & SecTemp(0, 1) & ""
DelStrings = AppendVectors(DelStrings, Link1)
H = H & Link1
' various icons that some have
H = H & WikiLink(SecTemp(0, 2)) & WikiLink(SecTemp(0, 3)) & IconCode(TOCiconCode, SecTemp(0, 4)) & IconCode(TOCiconCode, SecTemp(0, 5))
' start unordered list for this section
H = H & vbCrLf & vbCrLf & "
" & vbCrLf
End If
' recipe entry or cross-ref in this section
If 0 = InStr(TOCtemp(i, 4), " ") Then
H = H & "
" & TOCtemp(i, 5) & ""
' check if the recipe is new
If Now < 90 + CDate(ConvertDate(ReturnMatrixCell(DateAdded, f, 0, 1))) Then
H = H & " "
End If
H = H & vbCrLf
Else
H = H & "
" & TOCtemp(i, 4) & "" & vbCrLf
End If
' we have to close off the unordered lists
H = H & ReturnSlashULs(TOCtemp(i, 3))
NextRow:
Next i
' save: HTOC is for chapter pages
If Ctr = 1 Then
HTOC(k) = H
Ctr = 2
GoTo TOCStart
Else
' AllTOC is for all tables of contents on one page
' remove the links we don't want
For i = UBound(DelStrings) To 0 Step -1
strts = AllInStr(DelStrings(i), "<")
H = Replace(H, DelStrings(i), Mid(DelStrings(i), strts(1), strts(3) - strts(1)))
Next i
AllTOC(k) = H
End If
Next k
' ~~~~~~~~~~~~~ all chapter table of contents on one page, link to individual pages (Ctr=2 above) ~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building tables of contents on one page..."
H = "
PaleoFood: Table of Contents on One Page (" & (UBound(Recipes) + 1) & " Entries)
" & vbCrLf & vbCrLf
H = H & "" & vbCrLf & "" & vbCrLf & vbCrLf
H = H & "
" & vbCrLf
H = H & "
Page Contents:
" & vbCrLf & vbCrLf
H = H & "
" & vbCrLf
H = H & ReturnSearchString("paleofood.com/recipes")
H = H & "
" & vbCrLf & "
" & vbCrLf & vbCrLf
H = H & "
" & vbCrLf
LastGrp = ""
For i = 0 To UBound(Chapters)
' only topics and chapters not in a topic are included
If LastGrp <> Chapters(i, 3) Or Chapters(i, 3) = "" Then
H = H & "
" & vbCrLf & vbCrLf
InsertIntoHtm PaleoFoodPath & "\recipes.htm", H & Ravel(AllTOC, vbCrLf)
' ~~~~~~ remove non-recipe entries (the cross-references) ~~~~~~
For i = 0 To UBound(TableConts)
If InStr(TableConts(i, 4), " ") <> 0 Then
TableConts(i, 4) = ""
End If
Next i
TableConts = CompressRows(TableConts, , , , , "", 4)
' ~~~~~~~~~~~~~~~~ add photo data to Table of Contents ~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Getting photo information..."
' table of contents, old: 0-chapter, 1-group, 2-section, 3-/ULs, 4-recipe name; 5-recipe title
' add columns for: 6-piclevel, 7-picname, 8-picstr, 9-piccredit, 10-picalt, 11-width large pic, 12-height large pic
TableConts = AddColumns(TableConts, 7)
For i = 0 To UBound(TableConts)
' full recipe name
f = TableConts(i, 0) & "-" & TableConts(i, 4)
' check if page specific picture exists
temp = Array(".jpg", ".png", ".gif")
For j = 0 To UBound(temp)
If FileExists(PicPath & f & temp(j)) Then
TableConts = AddPicCredits(TableConts, PhotoCredits, i, 1, f & temp(j))
GoTo Found
End If
Next j
' look for ISBN in recipe and see if we have picture for it. we only take first if multiple
f = Recipes(Iota2(RecNames, f))
j = InStr(f, "https://www.amazon.com/dp/")
If j <> 0 Then
' extract ISBN/ASIN
f = Left(DropStr(f, j + 25), 10)
TableConts = AddPicCredits(TableConts, PhotoCredits, i, 2, f & ".jpg")
GoTo Found
Else
NoISBNs = AppendVectors(NoISBNs, res)
End If
' see if section has a picture we can use for the recipe
' --> need to implement for only first in section
f = TableConts(i, 0) & "-" & TableConts(i, 2)
If FileExists(PicPath & f & ".jpg") Then
TableConts = AddPicCredits(TableConts, PhotoCredits, i, 3, f & ".jpg")
GoTo Found
End If
' look for chapter picture
f = TableConts(i, 0)
If FileExists(PicPath & f & ".jpg") Then
TableConts = AddPicCredits(TableConts, PhotoCredits, i, 4, f & ".jpg")
End If
Found:
Next i
' save
NoISBNs = RemDupSameOrder(GradeUp(NoISBNs, , True))
H = ""
For i = 0 To UBound(NoISBNs)
H = H & "https://www.amazon.com/dp/" & NoISBNs(i) & vbCrLf
Next i
SaveIfChanged PFDataPath & "Book-ISBNs-without-images.txt", H
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ create chapter pages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building Chapter pages..."
For i = 0 To UBound(Chapters)
LastSec = ""
TOCtemp = CompressRows(TableConts, Chapters(i, 0))
ThumbTemp = CompressRows(ThumbData, Chapters(i, 0))
RPP(i) = UBound(TOCtemp) + 1
H = "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & Chapters(i, 1) & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
' subtitle
t = ReturnMatrixCell(SubHeads, Chapters(i, 0), 0, 1)
If t <> "" Then
H = H & "
" & t & "
" & vbCrLf
End If
' we have a flexbox for page contents heading on left and search box on right
H = H & "
" & vbCrLf
H = H & "
Page Contents:
" & vbCrLf & vbCrLf
' search button
H = H & "
" & vbCrLf
H = H & ReturnSearchString("paleofood.com/recipes")
' close flexbox
H = H & "
" & vbCrLf & "
" & vbCrLf & vbCrLf
' table of contents from before
H = H & HTOC(i) & vbCrLf & "
" & vbCrLf
' do we have below links?
t = ReturnMatrixCell(Belows, Chapters(i, 0), 0, 1)
If t <> "" Then
H = H & t & "
" & vbCrLf
End If
H = H & "
" & vbCrLf
' Amazon and other ad links
H = H & ReturnAmznAdCode(AmzAds, Chapters(i, 0), AmznTag, AdUsage)
' ~~~ recipes
For j = 0 To UBound(TOCtemp)
' do we have a section start?
If LastSec <> TOCtemp(j, 2) And TOCtemp(j, 2) <> "" Then
NewFlag = True
LastSec = TOCtemp(j, 2)
H = H & "
"
H = H & ReturnMatrixCell(Sections, TOCtemp(j, 0) & "-" & TOCtemp(j, 2), 0, 1)
' we add another link if chapter and section have external thumbnail links
If Not IsEmpty(ThumbTemp) Then
temp = CompressRows(ThumbTemp, TOCtemp(j, 2), 1)
If Not IsEmpty(temp) Then
H = H & " [Click for " & (1 + UBound(temp)) & " Recipe Links to Other Paleo Sites]"
End If
End If
H = H & "
" & vbCrLf & vbCrLf
Else
' this is just above recipe
H = H & "" & vbCrLf & vbCrLf
End If
' left side text
H = H & "
" & vbCrLf
' see if we can use a section picture. only first in section get section pictures
' --> this logic could be when getting pic data
If TOCtemp(j, 5) = 3 Then
If NewFlag Then
NewFlag = False
Else
TOCtemp(j, 5) = 0
End If
End If
H = H & "
" & TOCtemp(j, 5) & "
" & vbCrLf
f = TOCtemp(j, 0) & "-" & TOCtemp(j, 4)
H = H & Recipes(Iota2(RecNames, f))
' add our link line to the bottom
If 0 < InStr("123", TOCtemp(j, 6)) Then
t = "or Pin "
Else
t = ""
End If
H = H & " To Print " & t & "the Recipe, or to Post and/or Read Comments" & vbCrLf
H = H & "
" & vbCrLf
' if we have a picture
' columns: 6-piclevel, 7-picname, 8-picstr, 9-piccredit, 10-picalt, 11-width large pic, 12-height large pic
If TOCtemp(j, 6) = 1 Or TOCtemp(j, 6) = 2 Or TOCtemp(j, 6) = 3 Then
H = H & vbCrLf & "
" & vbCrLf
End If
H = H & vbCrLf
Next j
H = H & "" & vbCrLf & vbCrLf & "" & vbCrLf
SaveIfChanged PaleoFoodPath & "\" & Chapters(i, 0) & ".htm", H
Next i
' ~~~~~~~~~~~~~~~~~~~~~~~ create thumbnail pages for each chapter and the all page ~~~~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building thumbnail pages..."
temp = RemDupSameOrder(ReturnColumn(ThumbData, 0))
ReDim AllThumbCode(UBound(temp))
' loop for chapters that have thumbnail recipes
For i = 0 To UBound(temp)
' -> this should have sideways navigation, but there is only one chapter
' row in Chapters array
j = Iota2(ReturnColumn(Chapters, 0), temp(i))
ShortName = Chapters(j, 4)
t = ShortName & " Recipes at Other Paleo Sites"
ThumbTemp = CompressRows(ThumbData, temp(i))
H = "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & t & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
' -> remove style code when we have sideways navigation
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
' we save the heading code, as the next code is dual purpose
D = H
H = ""
' loop for sections
For j = 0 To UBound(SecCodes)
H = H & "" & vbCrLf
H = H & "
" & vbCrLf
H = H & "" & vbCrLf & vbCrLf
' loop for recipes in this section
SecTemp = CompressRows(ThumbTemp, SecCodes(j), 1)
For k = 0 To UBound(SecTemp)
H = H & "
" & SecTemp(k, 5) & ":" & vbCrLf
H = H & " " & SecTemp(k, 4) & "" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
Next k
Next j
' ~~ for all page we add the chapter and save for later
t = "
" & ShortName & "
" & vbCrLf
t = t & H
' fix chapter links
t = Replace(t, "href=""" & temp(i), "href=""../" & temp(i))
t = Replace(t, "src=""thumb", "src=""../thumb")
AllThumbCode(i) = t
' ~~ finish off chapter
H = D & H & "" & vbCrLf & vbCrLf
SaveIfChanged PaleoFoodPath & "\" & temp(i) & "-2.htm", H & "" & vbCrLf & "" & vbCrLf
Next i
' ~~~ AllThumbnails page
InsertIntoHtm PFDataPath & "\AllThumbnails.htm", Ravel(AllThumbCode)
' ~~~~~~~~~~~~~~~~~~~~~~~ all pictures on one page ~~~~~~~~~~~~~~~~~~~~~~~
CreateAllPicturesCode TableConts, PhotoCredits, Sections, RecNames
' ~~~~~~~~~~~~~~~~~~~~~~~ create individual recipe htm pages ~~~~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building Recipe htm pages..."
' ~~ build pages
For i = 0 To UBound(TableConts)
' table of contents, old: 0-chapter, 1-group, 2-section, 3-/ULs, 4-recipe name; 5-recipe title
' add columns for: 6-piclevel, 7-picname, 8-picstr, 9-piccredit, 10-picalt, 11-width large pic, 12-height large pic
' add word 'recipe' at end of title tag with logic
t = TableConts(i, 5)
' look for non-recipe entries
NotRecFlag = TableConts(i, 0) = "menus" Or TableConts(i, 0) = "convert"
NotRecFlag = NotRecFlag Or 0 <> InStr(t, "?") Or 0 <> InStr(t, "Suggest") Or 0 <> InStr(t, "Comment") Or 0 <> InStr(t, "Using") Or 0 <> InStr(t, "Intro") Or 0 <> InStr(t, "Discuss")
NotRecFlag = NotRecFlag Or Right(t, 4) = "etc."
NotRecFlag = NotRecFlag Or Left(t, 7) = "Subject"
If NotRecFlag Then
NotRecCount = NotRecCount + 1
End If
If 0 = InStr(UCase(t), "RECIPE") And Not NotRecFlag Then
t = t & " Recipe"
End If
RecName = TableConts(i, 0) & "-" & TableConts(i, 4)
H = "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & t & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
' identification by chapter-section level in upper left
H = H & "
" & vbCrLf
H = H & "
Chapter: " & ReturnMatrixCell(Chapters, TableConts(i, 0), 0, 1) & "" & vbCrLf
If TableConts(i, 1) <> "" Then
t = ReturnMatrixCell(GroupTitles, TableConts(i, 0) & "-" & TableConts(i, 1), 0, 1)
If t <> "" Then
H = H & " Group: " & t & "" & vbCrLf
End If
End If
H = H & " Section: " & ReturnMatrixCell(Sections, TableConts(i, 0) & "-" & TableConts(i, 2), 0, 1) & "" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
' in upper right, link and search input form
H = H & "
" & vbCrLf
H = H & ReturnSearchString("paleofood.com/recipes", "../")
H = H & "
" & vbCrLf
H = H & "
" & vbCrLf & vbCrLf
' the body of the page
H = H & "" & vbCrLf & vbCrLf
' the recipe text - the preformatted block
H = H & "
" & TableConts(i, 5) & "
" & vbCrLf
D = Recipes(Iota2(RecNames, TableConts(i, 0) & "-" & TableConts(i, 4)))
' any links to other recipes on another page need to be changed
' -> you cannot cross-link to a section
strts = AllInStr(D, "#")
If Not IsEmpty(strts) Then
For j = UBound(strts) To 0 Step -1
' exclude ones that are calling a table of contents name tag (toc-)
If (Not Left(DropStr(D, strts(j)), 4) = "toc-") And (Mid(D, strts(j) - 1, 1) <> """") And 0 < InStr("abcdefghijklmnopqrstuvwxyz", Mid(D, strts(j) + 1, 1)) Then
' e.g. "chapter.htm#recipe" goes to "chapter-recipe.htm"
k = InStr(DropStr(D, strts(j)), """") - 1
Link1 = Left(D, strts(j) - InStr(StrReverse(Left(D, strts(j))), "."))
D = Link1 & "-" & Left(DropStr(D, strts(j)), k) & ".htm" & DropStr(D, k + strts(j))
' -> this is where APL was saving internal links for later testing. but won't Total Validator get them?
' links that were on same page need to go to appropriate individual recipe page
ElseIf Mid(D, strts(j) - 1, 1) = """" Then
k = InStr(DropStr(D, strts(j)), """") - 1
D = Left(D, strts(j) - 1) & TableConts(i, 0) & "-" & (Left(DropStr(D, strts(j)), k)) & ".htm" & DropStr(D, strts(j) + k)
End If
Next j
End If
' links to images need to up a directory
D = Replace(D, "src=""images", "src=""../images")
' for links to other chapters lacking the #, we loop for chapter names
' ~~ loop for chapters
For j = 0 To UBound(Chapters)
' then search for each chapter name in recipe text
strts = AllInStr(D, """" & Chapters(j, 0) & ".htm""")
If Not IsEmpty(strts) Then
For k = UBound(strts) To 0 Step -1
f = DropStr(D, strts(k))
t = Left(f, InStr(f, """") - 5)
D = Left(D, strts(k)) & "../recipes.htm#" & t & DropStr(D, strts(k) + 4 + Len(t))
Next k
End If
' and any links into the table of contents
strts = AllInStr(D, """" & Chapters(j, 0) & ".htm#toc-")
If Not IsEmpty(strts) Then
For k = UBound(strts) To 0 Step -1
f = DropStr(D, strts(k))
D = Left(D, strts(k)) & ".#" & DropStr(f, InStr(f, "#"))
Next k
End If
Next j
' we have some custom link changes
k = InStr(D, """applesauce.htm""")
If k > 0 Then
D = Left(D, k) & "../" & DropStr(D, k)
End If
H = H & D & "
" & vbCrLf
' ~~ place pictures to the right if they exist
' columns: 6-piclevel, 7-picname, 8-picstr, 9-piccredit, 10-picalt, 11-width large pic, 12-height large pic
If TableConts(i, 6) <> "" Then
H = H & vbCrLf & "
" & vbCrLf
' image string (not closed)
t = "" & t & ">" & vbCrLf
' is there a credit?
If TableConts(i, 9) <> "" Then
H = H & "
" & TableConts(i, 9) & "
" & vbCrLf
End If
H = H & "
" & vbCrLf
End If
' user comments
H = H & vbCrLf & "" & vbCrLf & vbCrLf
H = H & ReturnDisqus(RecName) & vbCrLf
H = H & "" & vbCrLf
SaveIfChanged RecPath & RecName & ".htm", H
Next
' ~~~~~~~~~~~~~~~~~~~~~~~ build home page contents ~~~~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building home page..."
' needs recipes per chap and recipe/entry split
f = PaleoFoodPath & "\index.shtml"
InsertIntoHtm f, (1 + UBound(RecNames) - NotRecCount) & " Recipes in " & (1 + UBound(Chapters)), ""
InsertIntoHtm f, (1 + UBound(RecNames)) & " entries: " & (1 + UBound(RecNames) - NotRecCount) & " recipes and " & NotRecCount, ""
InsertIntoHtm f, Year(Now), ""
' build code to insert into page
LastGrp = ""
H = "
" & vbCrLf
' ~~~ the Table of Contents
H = H & "
" & vbCrLf & vbCrLf
H = H & ReturnSearchString("paleofood.com/recipes")
H = H & " " & vbCrLf
H = H & "
Chapters in Cookbook Order:
" & vbCrLf
H = H & "
" & vbCrLf
' ~~ loop for chapters
For i = 0 To UBound(Chapters)
' is this a new topic?
If Chapters(i, 3) <> LastGrp And Chapters(i, 3) <> "" Then
H = H & "
" & Chapters(i, 3) & ":" & vbCrLf
H = H & "
" & vbCrLf
LastGrp = Chapters(i, 3)
End If
' if the chapter name starts the same as the topic title, then we remove the word
t = Chapters(i, 2)
j = InStr(t, ":")
If j <> 0 Then j = j - 1
Link1 = Left(t, j)
j = InStr(Chapters(i, 3), " ")
If j = 0 Then
j = Len(Chapters(i, 3))
Else
j = j - 1
End If
Link2 = Left(Chapters(i, 3), j)
If Link1 = Link2 And Link1 <> "" Then
t = DropStr(t, Len(Link1) + 2)
End If
H = H & "
" & t & " (" & RPP(i) & ")" & vbCrLf
' does this chapter have more than four groups?
temp = RemDupSameOrder(ReturnColumn(CompressRows(TableConts, Chapters(i, 0)), 1))
If UBound(temp) > 4 Then
H = H & vbCrLf & "
" & vbCrLf
For j = 0 To UBound(temp)
t = ReturnMatrixCell(GroupTitles, Chapters(i, 0) & "-" & temp(j), 0, 1)
H = H & "
" & vbCrLf & vbCrLf
End If
' when in a topic we have to close out the chapters in its list
If i < UBound(Chapters) Then
If Chapters(i, 3) <> Chapters(i + 1, 3) And Chapters(i, 3) <> "" Then
H = H & "
" & vbCrLf & vbCrLf
End If
ElseIf Chapters(i, 3) <> "" Then
H = H & "
" & vbCrLf & vbCrLf
End If
Next i
H = H & "" & vbCrLf & "
" & vbCrLf & vbCrLf & vbCrLf
' ~~~ the links and ads at the right
' N.B. tweak the width so all just fits
H = H & "
" & vbCrLf
H = H & vbCrLf & "
" & vbCrLf & vbCrLf
' links above the ads
H = H & "
" & vbCrLf
H = H & " " & vbCrLf & vbCrLf
' the Ads
H = H & ReturnAmznAdCode(AmzAds, "index", AmznTag, AdUsage, "ad")
H = H & "
" & vbCrLf & vbCrLf
InsertIntoHtm f, H
' ~~~~~~~~~~~~~~~~~~~~~~~ all recipes on one page: 3 sorts ~~~~~~~~~~~~~~~~~~~~~~~
DoEvents
Application.StatusBar = "Building all recipes listed on one page..."
For i = 0 To UBound(TableConts)
' we need chapter names, so we put navigation names in the group column
TableConts(i, 1) = ReturnMatrixCell(Chapters, TableConts(i, 0), 0, 2)
' we need dates in TableConts to sort on them. we stick in column 6 (no longer needed)
TableConts(i, 6) = ReturnMatrixCell(DateAdded, TableConts(i, 0) & "-" & TableConts(i, 4), 0, 1)
Next i
' loop for sorts
For k = 1 To 3
H = ""
If k = 1 Then
f = "recipe"
TableConts = SortMatrix(TableConts, 4)
ElseIf k = 2 Then
f = "chapter"
TableConts = SortMatrix(TableConts, 1)
Else
f = "date"
TableConts = SortMatrix(TableConts, 6, , True)
End If
' loop by recipes
For i = 0 To UBound(TableConts)
' chapter title
Link1 = "
" & vbCrLf
If k = 1 Then
H = H & Link2
H = H & Link1
Else
H = H & Link1
H = H & Link2
End If
H = H & vbCrLf & "
" & ConvertDate(TableConts(i, 6)) & "
" & vbCrLf
H = H & "
"
Next i
' save
InsertIntoHtm PaleoFoodPath & "\" & f & "index.htm", H
Next k
' ~~~~~~~~~~~~~~~~~~~~~~~ all Amazon ads on one page ~~~~~~~~~~~~~~~~~~~~~~~
Application.StatusBar = "Building Amazon ads on one page..."
AmazonAds Chapters, AmzAds, AdUsage
AddNavCodeFromOtherSheet PaleoFoodPath & "\topnav.htm"
AddNavCodeFromOtherSheet PaleoFoodPath & "\site-building"
If RunSiteMap Then
BuildPaleoSitemap
End If
Beep
EndCode:
Application.StatusBar = False
End Sub
_____________________________________________________________________________________
Private Sub AmazonAds(ByRef Chapters As Variant, ByRef AmzAds As Variant, ByRef AdUsage As Variant)
' puts all Amazon ads on one page. showing usage analysis
' called by Process macro and a Dashboard button, for quick viewing of changes
Dim AdUsageBoolean() As Boolean
Dim D As String, f As String, H As String
Dim Ctr As Integer, i As Integer, j As Integer, k As Integer
f = PaleoFoodPath & "\site-building\"
' usage file
ReDim AdUsageBoolean(UBound(AmzAds))
' format page
For i = 0 To UBound(AdUsage)
H = H & "
"
If AdUsage(i, 0) = "index" Then
H = H & "Home Page"
Else
H = H & ReturnMatrixCell(Chapters, AdUsage(i, 0), 0, 2)
End If
H = H & "
" & vbCrLf & vbCrLf
' loop for ads in this chapter
For j = 1 To UBound(AdUsage, 2)
If AdUsage(i, j) = "" Then GoTo NextChapter
Ctr = Ctr + 1
H = H & "
" & vbCrLf
k = Iota2(ReturnColumn(AmzAds, 0), AdUsage(i, j))
If AmzAds(k, 1) = "" Then
MsgBox "No ad found for: " & AdUsage(i, j) & " in chapter: " & AdUsage(i, 0), vbCritical, "Page Creation Aborted"
Exit Sub
End If
AdUsageBoolean(k) = True
H = H & AmzAds(k, 1) & "
" & vbCrLf & vbCrLf
Next j
NextChapter:
Next i
' look for ads that were not used
D = ""
For i = 0 To UBound(AdUsageBoolean)
If Not AdUsageBoolean(i) Then
D = D & AmzAds(i, 0) & ", "
End If
Next i
If D <> "" Then
D = DropStr(D, -2) & "."
D = " The following ads were found in AmazonAds.txt, but were not in the AdUsage.txt file: " & D & " They could be duplicates."
End If
' add heading and ending and save
D = Ctr & " total ads (" & (UBound(AmzAds) + 1) & " unique ads used, on " & (UBound(AdUsage) + 1) & " PaleoFood pages.)" & vbCrLf & D & vbCrLf
InsertIntoHtm PaleoFoodPath & "\AllAmazon.htm", D & H & "
" & vbCrLf & "
" & vbCrLf
End Sub
_____________________________________________________________________________________
Private Sub UpdateOnlyAds()
' button on Dashboard
Dim f As String
f = PaleoFoodPath & "\site-building\"
AmazonAds ReadInDelimData(f & "Chapters.txt", "|"), ExtractData(f & "AmazonAds.txt", "*", 1), ReadInDelimData(f & "AdUsage.txt", ",")
End Sub
_____________________________________________________________________________________
Private Sub CreateAllPicturesCode(ByRef TableConts As Variant, ByRef PhotoCredits As Variant, ByRef Sections As Variant, ByRef RecNames As Variant)
' subfunction to ProcessPaleoFood
' inserts into AllPictures.htm
Dim Ctr As Integer, i As Integer, j As Integer, ISBNs As Integer
Dim H As String, p As String, PicName As String, PicPath As String, PicStr As String, t As String
Dim ChapList, PicMat, PicNames, PicTypes, SecList, temp As Variant
Application.StatusBar = "Building AllPictures Page..."
PicTypes = Array("Not Used", "Recipe", "Section", "Chapter", "Home Page")
' pictures that are not books and not full size (and get count of number of non-f excluded)
PicPath = PaleoFoodPath & "\pictures"
PicNames = SelectJpgs(PicPath, "-")
PicPath = PicPath & "\"
' remove the book/Amazon ones
For i = 0 To UBound(PicNames)
t = Left(PicNames(i), 1)
If t = "B" Or t = "0" Or t = "1" Or t = "8" Then
PicNames(i) = Empty
End If
Next i
ISBNs = UBound(PicNames)
PicNames = RemoveEmptiesInVector(PicNames)
ISBNs = ISBNs - UBound(PicNames)
' we need list of chapters and sections, to see if picture is in them
ChapList = RemDupSameOrder(ReturnColumn(TableConts, 0))
SecList = ReturnColumn(Sections, 0)
' TableConts: 0-chapter, 1-group, 2-section, 3-recipe name, 4-recipe title, 5-piclevel
' 6-picname, 7-picstr, 8-piccredit, 8-picalt, 10-width large pic, 11-height large pic
' we put all info in one big matrix:
' PicMat columns: 0-pic name, 1-pic size, 2-pic credits, 3-pic level, 4-pic type, 5-page section, 6-htm code
ReDim PicMat(UBound(PicNames), 6)
For i = 0 To UBound(PicNames)
PicName = RemoveExtension(PicNames(i))
PicMat(i, 0) = PicNames(i)
' get pic sizes
PicMat(i, 1) = ReturnFileSizes(PicPath & PicNames(i))
' PicCredit (some pictures won't have a credit)
PicMat(i, 2) = ReturnMatrixCell(PhotoCredits, PicName, 0, 1)
' PicLevel: 0-Not Used, 1-Recipe, 2-Section, 3-Chapter, 4-Home Page
If IsMember(RecNames, PicName) Then
PicMat(i, 3) = 1
ElseIf IsMember(SecList, PicName) Then
PicMat(i, 3) = 2
ElseIf IsMember(ChapList, PicName) Then
PicMat(i, 3) = 3
ElseIf PicName = "homepic" Then
PicMat(i, 3) = 4
Else
PicMat(i, 3) = 0
End If
' PicType - give PicLevel a label
PicMat(i, 4) = PicTypes(PicMat(i, 3))
' page section (we list in three categories)
If 0 < InStr(PicMat(i, 2), "/ 123RF") Then
PicMat(i, 5) = 2
ElseIf 0 < InStr(PicMat(i, 2), "FreeDigitalPhotos.") Then
PicMat(i, 5) = 3
Else
PicMat(i, 5) = 1
End If
Next i
' sort by byte size and credit (to be able to remove duplicates)
PicMat = SortMatrix(SortMatrix(PicMat, 2), 1)
' ~~~~ loop for pictures and build code for that picture
Ctr = 0
For i = 0 To UBound(PicMat)
' skip loop, if we just listed the dups in the prior picture
If Ctr > 0 Then
Ctr = Ctr - 1
GoTo NextLoop
End If
' ~~ image container
H = "
" & vbCrLf
' see if this picture has duplicates (test nexts for same size and credit)
' columns: 0-pic name, 1-pic size, 2-pic credits, 3-pic level, 4-pic type, 5-page section, 6-htm code
If i <> UBound(PicMat) Then
If PicMat(i, 1) = PicMat(i + 1, 1) And PicMat(i, 2) = PicMat(i + 1, 2) Then
AnotherDup:
Ctr = Ctr + 1
If i + Ctr + 1 <= UBound(PicMat) Then
If PicMat(i, 1) = PicMat(i + 1 + Ctr, 1) And PicMat(i, 2) = PicMat(i + 1 + Ctr, 2) Then
GoTo AnotherDup
End If
End If
End If
End If
PicName = RemoveExtension(PicMat(i, 0))
' picture string (not closed)
PicStr = "" & PicStr & ">" & vbCrLf
' pic credit
If PicMat(i, 2) <> "" Then
H = H & "
" & PicMat(i, 2) & "
" & vbCrLf
End If
' ~~ text container
H = H & "
" & vbCrLf
' if it is a recipe, we give the name a link
If Left(PicMat(i, 4), 1) = "R" Then
PicName = "" & PicName & ""
End If
' we add the type to the name string
PicName = PicName & " " & PicMat(i, 4) & vbCrLf
' see if any duplicates (we will skip these rows on next loop(s), so print now)
If Ctr > 0 Then
For j = 1 To Ctr
p = RemoveExtension(PicMat(i + j, 0))
If Left(PicMat(i + j, 4), 1) = "R" Then
p = "" & p & ""
End If
PicName = PicName & " " & p & " " & PicMat(i + j, 4) & vbCrLf
Next j
End If
H = H & PicName & "
" & vbCrLf
PicMat(i, 6) = H & "" & vbCrLf & vbCrLf
NextLoop:
Next i
' save count for heading (before removing empties)
Ctr = UBound(PicMat) + 1
' PicMat columns: 0-pic name, 1-pic size, 2-pic credits, 3-pic level, 4-pic type, 5-page section, 6-htm code
' remove the empties
PicMat = RemoveEmptyRowsInMatrix(PicMat, 6)
' sort by group then picture credit. now puts no credits at top, was at bottom
' -> could add arg to SortMatrix and GradeUp to put blanks at bottom
PicMat = SortMatrix(SortMatrix(PicMat, 2), 5)
' start HTML code
H = ISBNs & " ISBN/ASIN pictures excluded before processing." & vbCrLf
H = H & " " & Ctr & " pictures processed. " & UBound(PicMat) + 1 & " pictures are unique. "
H = H & Ctr - UBound(PicMat) & " pictures are not used. Most named with the prefix spare-."
' get list of pictures not used and not prefixed with space-
temp = ""
For i = 0 To UBound(PicMat)
If PicMat(i, 3) = 0 And Left(PicMat(i, 0), 6) <> "spare-" Then
temp = temp & PicMat(i, 0) & ", "
End If
Next i
If Len(temp) > 0 Then
temp = DropStr(temp, -2) & "."
End If
H = H & " Not labeled spares and not used in site processing: " & temp & vbCrLf
H = H & "
Jump to:" & vbCrLf & "
" & vbCrLf
j = AndDotEqual(PicMat, 5, 2)
H = H & "
123RF (" & j
H = H & " pictures, with " & AndDotEqual(PicMat, 5, 2, 3, 0) & " not used)" & vbCrLf
j = AndDotEqual(PicMat, 5, 3)
H = H & "
FreeDigitalPhotos.net (" & j
H = H & " pictures, with " & AndDotEqual(PicMat, 5, 3, 3, 0) & " not used)" & vbCrLf
H = H & "
" & vbCrLf & "
" & vbCrLf & "
" & vbCrLf & vbCrLf
' ~~~ loop for pictures (we could use Ravel, if we didn't have sections)
For i = 0 To UBound(PicMat)
H = H & PicMat(i, 6)
' is this a new section? gets a heading
If i <> UBound(PicMat) Then
If PicMat(i, 5) <> PicMat(i + 1, 5) Then
H = H & "
123RF Stock Photos"
Else
H = H & "free"">FreeDigitalPhotos.net"
End If
H = H & "
" & vbCrLf & "" & vbCrLf & vbCrLf
End If
End If
Next i
InsertIntoHtm PaleoFoodPath & "\site-building\AllPictures.htm", H
End Sub
_____________________________________________________________________________________
Private Function ReturnDisqus(RecName As String) As String
Dim H As String
H = "" & vbCrLf
H = H & "" & vbCrLf
End Function
_____________________________________________________________________________________
Private Function ReturnAmznAdCode(AmzAds As Variant, ByVal ChapName As String, AmznTag As String, AdUsage As Variant, Optional Suffix As String) As String
Dim j As Integer
Dim H As String, t As String
Dim temp As Variant
' is this chapter in the usage file?
temp = CompressRows(AdUsage, ChapName)
If IsEmpty(temp) Then Exit Function
' ~~ create string of all ads in this chapter
For j = 1 To UBound(temp, 2)
If temp(0, j) = "" Then GoTo FoundLast
H = H & "
" & vbCrLf
t = ReturnMatrixCell(AmzAds, temp(0, j), 0, 1)
' are we adding associate tags? link in data must end with either "&" or "/"
If AmznTag <> "" And 0 < InStr(t, "amazon") Then
t = Replace(t, "/"">" & vbCrLf & vbCrLf
Next j
FoundLast:
' after ads code
H = H & "
" & vbCrLf & vbCrLf
ReturnAmznAdCode = H
End Function
_____________________________________________________________________________________
Private Sub MoveRecipe()
' is button on Dashboard
' does not move within table of contents. that is done by hand in only the Table of Contents file
' -> untested
Dim Pflg As Boolean
Dim j As Integer
Dim D As String, Drec As String, f As String, NewChap As String, NewInput As String, NewRecipe As String
Dim OldChap As String, OldInput As String, OldRecipe As String
Dim res As Variant
OldInput = Range("OldRecipeName").Value
NewInput = Range("NewRecipeName").Value
If OldInput = "" Then
Range("OldRecipeName").Select
MsgBox "Must enter old recipe name.", vbCritical, "Aborted"
Exit Sub
ElseIf NewInput = "" Then
Range("NewRecipeName").Select
MsgBox "Must enter new recipe name.", vbCritical, "Aborted"
Exit Sub
End If
' split input
j = InStr(OldInput, "-")
OldChap = Left(OldInput, j - 1)
OldRecipe = Right(OldInput, Len(OldRecipe) - j)
j = InStr(NewInput, "-")
NewChap = Left(NewInput, j - 1)
NewRecipe = Right(NewInput, Len(NewRecipe) - j)
' "Warning: You moved within the same chapter"
' check that old input exists
Drec = ReadInFile(PaleoFoodPath & "\site-building\RecipeData.txt")
If InStr(Drec, OldInput) = 0 Then
Range("OldRecipeName").Select
MsgBox "Old name does not exist.", vbCritical, "Aborted"
Exit Sub
End If
' check new chapter exists
res = ReturnColumn(ReadInDelimData(PaleoFoodPath & "\site-building\Chapters.txt", "|"), 0)
If Not IsMember(res, NewChap) Then
Range("NewRecipeName").Select
MsgBox "New chapter does not exist.", vbCritical, "Aborted"
Exit Sub
End If
' change in RecipeData.txt
f = PaleoFoodPath & "\site-building\RecipeData.txt"
SaveFile f, Replace(Drec, OldInput, NewInput)
' change in DateAdded.txt
f = PaleoFoodPath & "\site-building\DateAdded.txt"
SaveFile f, Replace(ReadInFile(f), OldInput, NewInput)
SortDelimList f, "|", 0
' check for pictures (--> code can now handle only a single picture for a recipe)
f = PaleoFoodPath & "\pictures\" & OldInput & ".jpg"
Pflg = FileExists(f)
If Pflg Then
Name f As PaleoFoodPath & "\pictures\" & NewInput & ".jpg"
' change any photo credit
f = PaleoFoodPath & "\site-building\PhotoCredits.txt"
SaveIfChanged f, Replace(ReadInFile(f), OldInput, NewInput)
End If
' add permanent redirect record in .htaccess
f = PaleoFoodPath & "\.htaccess"
SaveFile f, ReadInFile(f) & "Redirect 301 /recipes/" & OldInput & ".htm /recipes/" & NewInput & ".htm" & vbCrLf
' delete old recipe from my folder
Kill PaleoFoodPath & "/recipes/" & NewInput & ".htm"
End Sub
_____________________________________________________________________________________
Private Sub SplitPaleoVBACode()
' is button on dashboard
VBAtext2Text PaleoFoodPath & "\site-building\VBA-code.txt"
End Sub
_____________________________________________________________________________________
Private Sub SortAdList()
' is button on dashboard
SortDataFile PaleoFoodPath & "\site-building\AmazonAds.txt"
End Sub
_____________________________________________________________________________________
Private Function ReturnSlashULs(Count As Variant) As String
If Count = 0 Or Count = "" Or Len(Count) > 1 Then Exit Function
Dim i As Integer
Dim H As String
For i = 0 To Count - 1
H = H & "" & vbCrLf
Next i
ReturnSlashULs = H & vbCrLf
End Function
_____________________________________________________________________________________
Private Function ConvertDate(ByVal D As String) As String
' converts date from yyyymmdd to mm/dd/yyyy
D = Mid(D, 5, 2) & "/" & Right(D, 2) & "/" & Left(D, 4)
If Left(D, 1) = "0" Then
D = " " & DropStr(D, 1)
End If
ConvertDate = D
End Function
____________________________________________________________________________________