Getting Started
Generate a site from a template
To get started with Franklin, you can use the FranklinTemplates.newsite
function in a Julia REPL.
That function will generate a website folder on your computer that's ready
to be built by Franklin, and that you can modify at will:
using FranklinTemplates: newsite
using Franklin, FranklinTemplates
newsite("TestWebsite"; template="hyde")
The execution of this command will also move you to that folder (i.e. cd TestWebsite/
).
The first argument of newsite
is the title of the folder that will be created,
and moved to (you can change that later).
If you are already in a folder that you previous created for this purpose, just indicate the
current path with "."
(i.e.: newsite(".", ...)
).
The template=
keyword argument allows you to specify one of the few
simple templates
that can get you started with Franklin.
In particular, if you just want a super basic template to experiment with, the
"sandbox"
template should prove useful.
Building and editing the website
Once you have a website folder — e.g. TestWebsite
— you can start the Franklin
server from within it:
serve() # or serve("path/to/TestWebsite")
[...]
β LiveServer listening on http://localhost:8000/ ...
(use CTRL+C to shut down)
You can now visit your site at http://localhost:8000
(the page should have been
opened automatically in your browser).
At a high level, the serve
function does the following:
- goes through all your pages in a first initial pass and (re)builds them if necessary,
- starts LiveServer which
- starts a browser,
- watches files for changes and reloads updated pages.
There's a number of keyword arguments to serve
which you might find useful, do ?serve
in your REPL to get the relevant docstring.
Modifying files
Once the server is running, you can edit the file index.md
and see the effect it
has in your browser.
If you're familiar with Markdown, this step should hopefully be fairly intuitive.
Otherwise, you might want to check out the Markdown basics.
The index.md
file also has a few indications for how to do things which you might
find useful.
Once you have a feel for things, you might want to check out the Franklin-specific extensions and related topics.
Interrupting and restarting the server
You can interrupt the server at any time by hitting Ctrl + C in the Julia REPL.
And, of course, you can re-start it with serve(...)
.
Passing launch=false
to serve
can be convenient as you may already have a
browser tab pointing to the right address (e.g. localhost:8000
) and may not want to open
a new one every time you restart the server.
Page structure
Head/Foot structure
When using Franklin, it is useful to have a rough understanding of how the HTML pages are generated. For a source page with the following Markdown:
# Hello
Some **text** here.
a HTML page will (typically) be generated with the following structure:
ββββββββββββββββββββββββββββββββββββββββββββββββ
β ββββββββββββββββββββ β
β β <!doctype html> β β
β β <html lang="en"> β β
β β <head> β β
β β ... β (_layout/head.html) β
β β </head> β β
β β <body> β β
β β ... β β
β ββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β <h1>Hello</h1> β β
β β <p>Some <strong>text</strong> here.</p> β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββ β
β β ... β β
β β </body> β (_layout/foot.html) β
β β </html> β β
β ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ
The top box corresponds to the file _layout/head.html
in your website folder.
Correspondingly, the bottom box corresponds to the file _layout/foot.html
.
The middle box is the HTML that is generated by Franklin when converting the source Markdown.
Note that what gets effectively placed at the "top" or "bottom" of your page can be finely controlled via page variables but, for now, the important bit is just to have this simple high-level view in mind.
Skeleton structure
Though the head.html
/foot.html
approach above is recommended as it allows re-using the
head.html
and foot.html
elsewhere, including in raw-HTML pages, by doing
{{insert head.html}}
Your HTML here
{{insert foot.html}}
some users might prefer having a single _layout/skeleton.html
file which describes the structure of pages.
For instance it could look like
<!doctype html>
<html lang="en">
<head> ... </head>
<body>
{{page_content}} <!-- this inserts the partially converted Markdown -->
</body>
</html>
and so, instead of separating the head, content and foot, it's a single file where you just indicate where the content goes.
If you do have a skeleton file in your _layout
folder, and also have a head and foot files, only the skeleton will be considered.
Next steps
Now that you have a working website that you can render locally and experiment with,
you should try to further modify the .md
file(s) in the folder, and the .html
files in the
_layout
folder, and try to get an intuition for how things work.
The rest of the docs is there to help you when things don't work like you might expect them to. You may also want to:
- join the
#franklin
channel of the Julia Slack to get help with small questions quickly, - ask questions on the Julia Discourse adding the tag
franklin
, and - open issues in the repository if you encounter a bug.