Multiple Files in an Outline

I have started using Hugo a Markdown based static web Site Generator - It uses a standard directory structure for it’s conversion to a Static Site. I would, or course like to use folding text and it would be super nice if I could simply pull the whole directory structure into folding text so that I can use the outlining capabilities to organize my existing posts -

Is there a plugin or easy way to do this?

What is the mapping and the round-trip that you have in mind ?

Mapping – for example, Folders become nested FT headers, file names unordered (bulleted) list items, and file contents body text ? Something else ?

Round trip – do you mean that you want to re-export (post reorganisation) with the same mapping back to folders and files ?

Does Brett Terpstra’s Planter script look relevant to the workflow you are thinking of ?

I glanced at Planter but I am more concerned with reading into an outline or exporting sections for example suppose I write a series of Blog posts about folding text;

## Folding Text
### Installing Folding Text
### Using Folding Text
### Advanced Folding Text

My Hugo Directory structure would be something like this:

C:/hugo/content/posts/foldingtext/install.md
C:/hugo/content/posts/foldingtext/using.md
C:/hugo/content/posts/foldingtext/advanced.md

It’s an interesting process - reorganising and re-segmenting a tree of text files …

Not something I will personally be able to get to this week, but I suppose my first guess would be to:

  1. Draft something in Bash or Python to to walk a directory tree and assemble a large text outline in which the contents of each incoming .txt | .md | .ft file are tab indented one level further than the nodes which represent the names of the containing files

  2. Post reorganisation of the large outline, to mark outline nodes which should now become folders and files with tags like @folder and @file

  3. Run a script which asks you to specify an output folder, and then creates a new directory structure under it, populating the new folders and text files according to the @folder and @file tags in the outline.

If no-one else has done anything similar by October, I might give it a look, one evening … I can imagine uses for something along those lines myself.

Rob

I thought this sounded like something I would use. I have a flat file system markdown based website also (I wrote it myself in go). So, a handy tree creator for looking at the site is just what I wanted. I spent 15 minutes and came up with SiteLayout program in ruby. I added it to my Alfred workflow for FoldingText that you can get from my GitHub: https://github.com/raguay/MyAlfred

The program is:

#!/usr/bin/ruby

#
# Program: 			SiteLayout.rb
#
# Description: 	This program will create a site map of files
#  					for a flat file system web site. Files that
#                 FoldingText can open will have links for it to
# 						open them. Directories and other files will be
# 						linked to be opened in Finder.
#
# Setup some basic variables to use.
#
# baseDir		The beginning of the website
# wfile			The file to write the information into
# tfill			The character to use to tab fill on the left.
#
baseDir = "<path to the site directory>"
wfile = "test.ft"
tfill = "\t"

#
# If there are command line arguments for the directories, then use them.
#
if ARGV.count == 2
    baseDir = ARGV[0]
    wfile = ARGV[1]
end

#
# Function: 		extractDirLevel
#
# Description: 	This function will extract the directory starting from the right
# 						to the left for level depth. It will then return the resulting
#                 string
#
def extractDirLevel( base, level )
    $parts = base.split('/')
    $total = $parts.count
    $i = $total - level
    $result = ""
    while ($i < $total) do
	    $result += $parts[$i] + "/"
	    $i += 1
    end
    return $result
end

#
# Function: 		LayoutDirectory
#
# Description: 	This function will take a base directory, current level, and
# 						a tab fill character to create a directory layout document for
# 						FoldingText. Files will be clickable to open in FoldingText if
# 						it is the proper type, otherwise it will open a directory to
# 						the file. Directories will have links to that directory.
#
def LayoutDirectory( base, level, tabf )
    #
    # Print out the base directory. If this is the first level, then
    # print the full thing. Otherwise, print an abbreviated directory
    # name, but use the full path for the link.
    #
    if(level == 0)
	    result = "".rjust(level,tabf) + "[#{base}](#{base}) @dir\n"
    else
	    lbase = extractDirLevel(base,level)
	    result = "".rjust(level,tabf) + "[#{lbase}](#{base}) @dir\n"
    end
    #
    # Here on out, level needs to be one deeper.
    #
    level = level + 1
    Dir.foreach(base) { |fname|
	    #
	    # Ignore basice directories that are not needed.
	    #
	    if (fname != ".") && (fname != "..") && (fname != ".DS_Store")
		    if File.directory?(base + "/#{fname}")
			    #
			    # It is a directory. Go a level deaper.
			    #
			    result += LayoutDirectory(base + "/#{fname}", level, tabf)
		    else
			    #
			    # Fix the file name to not have spaces.
			    #
			    nName = "#{base}/#{fname}".gsub(" ","%20")

			    #
			    # Get the file extension and create the link based on it.
			    #
			    ext = File.extname(fname)
			    if (ext == ".ft") || (ext == ".md") || (ext == ".html") || (ext == ".txt") || (ext == ".json")
				    #
				    # It is a file that FoldingText can edit. Set the link for opening in FoldingText.
				    #
				    result += "".rjust(level,tabf) + "[#{fname}](ftdoc://#{nName}?line=1) @file\n"
			    else
				    #
				    # It is a file that FoldingText does not open. Set to open in Finder.
				    #
				    result += "".rjust(level,tabf) + "[#{fname}](file://#{nName}) @file\n"
			    end
		    end
	    end
    }
    return result
end

#
# If the result file already exists, remove it.
#
if File.exists?(wfile)
    File.delete(wfile)
end

#
# Write the resulting string to the file.
#
File.open(wfile, 'w') {|f|
    f.write(LayoutDirectory( baseDir, 0, tfill))
}

I added a description of the new function to my website: http://customct.com/alfred-2-workflows

To open the files in FoldingText, you have to have the FoldingText URI handler installed. That function is built into the workflow as well.

Let me know if this is close to what you were thinking? It is already helping me edit my site!

Awesome

Now I have to upgrade my Alfred

Thanks

You can just run the script above. The URL handler is part of @complexpoint work. You can get it from his GitHub: https://github.com/RobTrew/txtquery-tools/tree/master/ftdoc%20url%20scheme%20and%20FTCopyAsURL

But, if you update Alfred, you will have a lot of workflows to use that make life so much easier on the Mac! I love it.

I upgraded the script in the Alfred workflow to put the “#” at the front of all the directories. In the above script, just add:

"".rjust(level,"#") + 

To the directory assignments. They should look like:

if(level == 0)
    result = "".rjust(level,"#") + "".rjust(level,tabf) + "[#{base}](#{base}) @dir\n"
else
    lbase = extractDirLevel(base,level)
    result = "".rjust(level,"#") + "".rjust(level,tabf) + "[#{lbase}](#{base}) @dir\n"
end

This just makes it a little easier to fold and to standout a little more.

The workflow also allows for viewing the markdown file documenting the URI standard. It’s in the “ft:docs” command.

Okay, I just upgraded the Alfred workflow to add links making use of the Alfred URI handler to call external commands. Now, the Site Layout command will create the layout with all directories opening in Alfred browser and all non-Markdown or non-HTML files in their default program (ie: graphics will open in their graphic program.). The Alfred URI handler has to be installed for that functionality. You can get it at the same places (Alfred Forums, Packal, or my web site).

Is this the functionality you were looking for? It sure has helped my blogging.

Wow amazing - I will give it a try - I have had Alfred for a long time but I didn’t do anything more than open applications - Now I am using it for everything - I also need to get going on some blogging

Thanks