Tag: Docs (8 posts)

Site Structure

Default Site Structure

You can create a default site with the “new” command, which will have the following basic structure:

|_ magnet
    |_ images
    |_ indices
    |_ posts
        |_ posts.yaml
        |_ hello.md
        |_ (...more posts and post directories)
    |_ static
    |_ temp
    |_ themes
        |_ propeller-3.0
            |_ templates
            |_ assets
    |_ site.yaml

These are the default locations but can be overridden in the site.yaml.

Of particular note are the “images” and “static” directories, you may want to have these somewhere else entirely, for instance, if you have nginx serving from a www-data directory you’ve already setup.

But you should be able to begin right away by using the existing defaults.

Posts Structure

The “posts” directory contains the markdown for posts.

The name of the directory “posts” here is arbitrary — it can be called anything as long as it is:

• a subdirectory of “magnet”

• has its own posts.yaml file inside of it.

There can be multiple “posts” directories. These are searched for recursively.

This allows for some organization of posts on your part and maybe some portability if you are using or collecting the markdown from other sources. For instance, a script that reads Instagram’s API and writes markdown files into a directory called “instaposts” or something. For instance:

|_ magnet
    |_ images
    |_ insta-posts
        |_ posts.yaml
        |_ (...various md files)
    |_ my-blog
        |_ posts.yaml
        |_ (...various md files)
        |_ my-topic
            |_ posts.yaml
            |_ (...various md files)
    |_ joes-posts
        |_ posts.yaml
        |_ (...various md files)
    |_ static
    |_ themes
    |_ indices
    |_ site.yaml

Settings Structure

Settings are kebab-case yaml. There are two type of settings files, “site.yaml” and “posts.yaml”.

See the Post Settings Field Reference for those yaml files.

See the Site Settings Field Reference for the primary site settings yaml.

Themes and Templates

Themes

Themes are simply sets of assets like css and templates. These are grouped into named folders. Using a theme means declaring the name of the theme directory in the settings file. See “theme-name” in site settings.

Templates

Using the Go templating format.

Debugging problems in Go templates can be frustrating. Forget the final “{{end}}” in your conditions? Yeah, Go is gonna explode without much help. Use what I’ve put in demo generated by “go-magnet new” as a starting point.

In the source code, see structs.go particularly PageData and Pagination structs for specifics, as well as the Post struct.

PageData

When a page is built using a template, magnet populates some PageData for you to use in the templates.

https://codeberg.org/83h3m07h/go-magnet/src/branch/master/structs.go#L84

Author

String. Author name (if any).

Authors

[]ByNameAsc,ByCountDesc. See ItemsCount in structs.

AuthorsByName

[]Name,Slug,Count. See ItemsCount/NameCount in structs.

AuthorsByCount

[]Name,Slug,Count. See ItemsCount/NameCount in structs.

Endpoint

String. Possible values:
+ “tag”
+ “rss-tag”
+ “author”
+ “rss-author”
+ “post”
+ “custom”
+ “home”
+ “rss-home”
+ “archive”

MagnetURL

String. URL to the git repo.

PageName

String. A title if there is one.

PageTags

[]Strings. A list of unique tags contained in the entries of this page.

PageTitle

String. The SiteName and relevant string.

Pagination

Struct Pagination. See Pagination in structs.

Posts

[]Post. A list of Posts. See Post in structs.

SiteName

String. Set by settings.SiteName

SiteRemoteAddress

String. Set by settings.SiteRemoteAddress

Tag

String. The currently set Tag (if any).

Tags

[]ByNameAsc,ByCountDesc. See ItemsCount in structs.

TagsByName

[]Name,Slug,Count. See ItemsCount/NameCount in structs.

TagsByCount

[]Name,Slug,Count. See ItemsCount/NameCount in structs.

ThemeName

String. The name of the theme.

Version

String. The go-magnet version.

Router Endpoints

The server router can be found here.

Endpoint Patterns

ID

lowercase a-z, uppercase A-Z, numerals 0-9, between 2 characters and 64 characters

page numbers

numeric 0-9, between 1 and 12 digits

Available Endpoints

home

/
/page/(pageNum)/
/index.xml

tag

/tag/(SLUG)/
/tag/(SLUG)/page/(pageNum)/
/tag/(SLUG)/index.xml

author

/author/(SLUG)/
/author/(SLUG)/page/(pageNum)/
/author/(SLUG)/index.xml

post

/post/(ID)/

archive

/archive/

robots

/robots.txt

custom pages

/s/(ID)/

assets

/assets

images

/images

page 2 of 2 « previous