Giter Club home page Giter Club logo

cryogen-core's Introduction

cryogen-core

Dependencies Status

Cryogen's compiler.

Leiningen

Clojars Project

License

Copyright ยฉ 2014-2020 Carmen La

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

cryogen-core's People

Contributors

artiavis avatar benswift avatar bombaywalla avatar devth avatar dl1ely avatar dominicfreeston avatar holyjak avatar j0ni avatar jerger avatar jstepien avatar kingmob avatar kremers avatar lacarmen avatar madstap avatar markokocic avatar matsu911 avatar mcurence avatar nbardy avatar niamu avatar ponkore avatar sankara avatar seancorfield avatar seanirby avatar simon-brooke avatar svmbrown avatar tankanow avatar tuhlmann avatar uhnuser avatar wjlroe avatar yogthos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cryogen-core's Issues

Add active page to config map

On some pages, like the home page, a key is added to the map so it can be used in templates to determine if it's the page currently being rendered. In complier.clj:

(render-file "/html/home.html"
                     (merge params
                            {:home    true
                             ...

And used in the base template:

<div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li {% if home %} class="active" {% endif %}><a href="{{index-uri}}">Home</a></li>

I want to add a link to the tags page in the navigation bar, but there isn't a key added to the map for the tags page so there's no way to conditionally add the "active" class. A key could be added to the map, although I'm not sure of a name because "tags" is already used. Therefore I was thinking maybe the page name should be stored instead of a custom key with a boolean for each page. So compiler.clj would be like:

(render-file "/html/home.html"
                     (merge params
                            {:active-page    "home"
                             ...

And could be used like:

<ul class="nav navbar-nav">
    <li {% ifequal active-page "home" %} class="active" {% endifequal %}><a href="{{index-uri}}">pages</a></li>

Thoughts?

Sass file detection doesn't seem to work

I discovered Cryogen today and so far it's been fairly easy to work with, but I'm having a slight issue with the Sass support. From the docs:

  • sass-src - directory containing sources of sass files to be compiled - defaults to "css" - be sure to include this directory in your resources section
  • sass-dest - directory where the compiled output CSS would be put into. defaults to "css" - be sure to include this directory in your resources section

Based on that, if I put a .scss/.sass file in the css folder, it should be compiled into CSS as <file>.css. However, the result is that the file is copied verbatim - .scss/.sass extension and untouched content.

Looking at the source, there should be a "Compiling Sass File: ..." message after "compiling sass", however all I get is:

...
generating rss
compiling sass
"Elapsed time: 560.228842 msecs"

If I add an "else" condition to (if (seq sass-files), e.g. (println "No Sass files found"), then I get:

generating rss
compiling sass
No Sass files found
"Elapsed time: 861.302887 msecs"

I don't really have time at the moment to look into it further, though.

Commit 510c33c Fails to Compile on Windows 10

I pulled the latest Cryogen Core on Windows 10 and am unable to compile the code, but when I revert to the parent commit, I can.

510c33c

I assume that (str ^java.io.File page) calls getPath as indicated in the JavaDocs, which appears to return the absolute path (at least) on my Windows machine. Perhaps it returns a relative path on *nix machines?

Traceback looks something like...

clojure.core/pmap/fn/...
cryogen-core.compiler/read-posts/fn/...
cryogen-core.compiler/parse-post....
cryogen-core.compiler/parse-post-date....
java.text.DateFormat.parse...
java.text.ParseDateException: Unparseable date: "C:\Documen"

At any rate, and as I raised in #73, naive path regex does not appear portable in JVM languages. This should be reimplemented, perhaps in terms of the existing Java file API's?

Refactor project structure to be less deep

Get rid of the resources directory and just have public and templates on the top level.

/resources/public -> /public
/resources/templates -> /templates

Perhaps themes should be a top level directory as well? (I'm not sure about this one yet)

Adding a new LESS CSS plugin

The reference code repo

https://github.com/zerg000000/cryogen-less.git

It required one lines of changes in the core project( the dorun line).

    (sass/compile-sass->css!
     {:src-sass sass-src
      :dest-sass (str "../public" blog-prefix "/" sass-dest)
      :ignored-files ignored-files
      :base-dir "resources/templates/"})
    (dorun (map #(apply (resolve (symbol %)) [config]) (:extra config)))))

Support TOCs with inline `code`

If I have backtick-delimited code in a heading, the table of contents is broken.

Here's a small reproducible test case. With the following post markdown:

{:title "A Cryogen feature request: TOCs that include headings with backticks"
 :layout :post
 :tags ["cryogen"]
 :toc true}

## A heading without code

## A heading with some `code` included

## Another heading without code

I see the following rendering. Note that the middle item in the table of contents does not match its heading.

toc with inline code

Thanks for your work on Cryogen, by the way. It looks pretty neat. ๐Ÿ˜„

FileNotFoundException (File used by another process)

I am using Sublime Text to edit posts. Occasionally, i get this when saving in ST with lein ring server running:

Exception in thread "Thread-0" java.io.FileNotFoundException:     resources\templates\asc\posts\.suble12.tmp (The process cannot access the file because it is being     used by another process)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at pandect.algo.md5$eval6586$fn__6587.invoke(md5.clj:60)
    at pandect.algo.md5$eval6559$fn__6560$G__6550__6565.invoke(md5.clj:9)
    at pandect.algo.md5$eval6614$md5__6627.invoke(md5.clj:116)
    at clojure.core$map$fn__4245.invoke(core.clj:2559)
    at clojure.lang.LazySeq.sval(LazySeq.java:40)
    at clojure.lang.LazySeq.seq(LazySeq.java:49)
    at clojure.lang.Cons.next(Cons.java:39)
    at clojure.lang.RT.next(RT.java:598)
    at clojure.core$next.invoke(core.clj:64)
    at clojure.core$zipmap.invoke(core.clj:2791)
    at cryogen_core.watcher$checksums.invoke(watcher.clj:16)
    at cryogen_core.watcher$watch_assets.invoke(watcher.clj:27)
    at cryogen_core.watcher$start_watcher_BANG_$fn__10797.invoke(watcher.clj:33)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.lang.Thread.run(Thread.java:745)

I see it seems to have something to do with the temp file ST drops in the posts directory, and that the exception originates from somewhere inside pandect.algo.md5, but perhaps cryogen can do something about it?

After the exception, lein ring server does not continue watching the directory ๐Ÿ˜ž

Changing `:public-dest` seems to break CSS/JS access

I switched the value of :public-dest from public to docs and the contents of docs/css and docs/js have now become invisible. I'm using the "blue" theme, and screen.css doesn't load anymore. Ditto for highlight.pack.js. The files are there in docs/css and docs/js, but they're not found by the browser.

Any idea why that's happening?

Thanks in advance.

Refactor compiler to separate impure and pure code

Currently the compiler has quite a bit of io spread out in many functions. It would be nice to refactor it into three distinct phases.

  • reading posts, pages and the config into a data-structure
  • transforming that data structure into a new one
  • writing the transformed data structure to disk

All the difficult things are moved into the pure middle part, which becomes a lot more convenient to test and nicer to work with in general. (It's probably not necessary to be militant about purity, the printlns that are scattered around are kind of nice.)

The output data structure could be a map from url to finished html. There's a quite nice library that takes a data structure like that and either writes it to disk or serves it locally with ring. Using that we could save quite a bit of code in the compiler and, more importantly, code in the template.

It also has some other niceties.

  • Reporting on conflicting urls.
  • Reporting on differences in the built files.

Any thoughts on this?

Contents lost when :blog-prefix in config.edn is blank

I'm trying Cryogen with no blog-prefix (in my config.edn, :blog-prefix is nil).Under the condition, (Markdown/Asciidoc) contents are not compiled to output HTML.

I tried to fix this problem, I found a bug in markup/rewrite-hrefs.When :blog-prefix in config.edn is set nil or "", rewrite-hrefs always returns nil.

Sass doesn't apply to themes' css/ directory

I was a bit confused why the Sass files in my theme's css folder weren't compiling. The docs just say the Sass directory config defaults to css, and since there isn't one under resources/templates/ by default, I assumed it was referring to the css directory in the template instead.

I could compile Sass to CSS in the theme in advance, but I'd prefer to build everything at once, if possible. I also tried specifying the Sass paths to use public/blog/css, but Cryogen only looks under templates/ at the moment.

I'm happy to do this if you want a PR. Perhaps using :sass-theme-src and :sass-theme-dest to indicate Sass dirs relative to the theme? Or make :sass-src and :sass-dest accept multiple directories?

Sitemap Generation Loc Broken on Windows

This is a pretty straightforward fix. The naive regex in sitemap.clj prevents this from working on Windows, because the paths are given in UNIX format. This shouldn't be too hard to fix, but unfortunately, there isn't anything like Python's os.path.join and os.path.split that I'm aware of. Could conceivably be "brute-forced" by switching on java.io.File#seperator, but might be cleaner to create helper methods using the java.io.File API directly.

(defn loc [^java.io.File f]
(-> f (.getAbsolutePath) (.split "resources/public/") second))

broken sass compilation

Currently, I can't compile sass files.

compile-sass->css! gets nil for the sass-dest argument, because the key in the map passed in by compile assets is actually dest-sass.

Prevent klipse to emit empty html content

When :klipse is set to {} (or not present at all) in config.edn, it will emit this code:

<link rel="stylesheet" type="text/css" href=nil>
<script>
window.klipse_settings = null;
</script>
<script src=nil></script> 

where browser will fail with GET request for given resource, which is nil. Here is a small patch to mitigate this (I've added it against blue_centered theme, but should be applicable to other themes as well):

--- a/resources/templates/themes/blue_centered/html/base.html
+++ b/resources/templates/themes/blue_centered/html/base.html
@@ -86,7 +86,9 @@
 <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
 {% script "js/highlight.pack.js" %}
 <script>hljs.initHighlightingOnLoad();</script>
+{% if klipse|not-empty %}
 {% if post.klipse %} {{post.klipse|safe}} {% endif %}
 {% if page.klipse %} {{page.klipse|safe}} {% endif %}
+{% endif %}
 </body>
 </html>

<!--more--> marker is not recognized

I have tested with a blank install and changed the following files as follows:

resources/templates/config.edn

{...
  :blocks-per-preview 10
  :previews? true
 ...}

resources/templates/md/posts/docs.md

 :layout :post
 :tags  ["cryogen"]
 :toc true}

This intro only documents a subset of Cryogen's features. For additional documentation please see the [cryogen site](http://cryogenweb.org).
<!--more-->
## Features
...

The blog index page looks as follows (clearly not cutting off after the first line)

cropped-cryogen

Please let me know if I have done something incorrect here which is causing the marker to not be recognized.

Thanks!

toggle sub-directory support in posts and pages

@matsu911 @lacarmen would you be open to / is there a way we can make sub-directory support in posts and pages a toggle in the config.edn? in 0.1.38 i used to rely on the fact that subdirs were searched for posts but not reflected in the url.

example: /posts/2016/cool-post.md would yield a url of /cool-post but now yields a url of /2016/cool-post

being able to group posts by year was a nice way to organize without having the date in the url.
510c33c

Submodule conflict

Hello guys, I've recently started learning Clojure and decided to checkout this Cryogen to setup a self reference blog.

I'm trying to automate my workflow, and I tried to setup the gh-pages branch into a git submodule. The point is avoiding to have to copy paste code between folders, and the idea is simple:

  • Master ignores public/my-project
  • public/my-project is added as a submodule pointing to the gh-pages branch
  • Everytime the generated static code changes, those file get written only on the public/my-project folder, we can commit and push a new version to the gh-pages.

At the moment this doesn't work thought ๐Ÿ˜ž

As I said I'm a Clojure rookie, but I think the issue is that the wipe-public-folder function in cryogen-core deletes the .git folder in the submodule folder, so it doesn't know that it's a submodule and supposed to point to the gh-pages anymore. I might be wrong there, because I see that a filter is done based on keep-files, but nevertheless the public/my-project point to gh-pages when setup with git submodule add -b gh-pages https://github.com/<username>/<project>.git public/my-project and has a .git folder, and as soon as the local server regenerates the static content the .git folder is gone.

Unfortunately I cannot yet submit a PR with a fix for the issue, but I'm happy to provide more details. The project repo is https://github.com/mokagio/podcasts-notes, and I mainly followed this guide to understand how to setup the submodule workflow.

Thanks

Expose posts variable for the index page, posts preview

Right now, the base.html is assuming there is a one single post per page, with next/prev links. Would be nice to have posts variable available in base.html to support custom themes. Right now we have latest-posts, which is not enough.

Also, good to have a new config variable, :posts-per-page 4, or similar, for example, where we set how many post previews to display per page. And the posts filled in posts variable are changing dynamically every time we navigate next/prev, like, blog.com/p/2 (second page), and the variable saying total number of pages with posts based on the :posts-per-page size. And default blog.com or blog.com/index.html, assumes that the page number is 1.

It also requires to introduce extra preview field to the post variable itself, to display part of the post as preview (maybe even configurable from the post.md itself somehow, maybe adding a new param :preview-lines 10, for example).

And, extra one is to document all the variables available for the theme authors: like latest-posts, navbar-pages (why it is not called just pages?), etc., and the structure overview of all the availale fields of each map/variable, like title, name, for post, page, etc.

`parse-post-date` fails when posts are stored in subdirectories without `:date` key in post metadata

To reproduce:

  1. Start with a fresh Cryogen template
  2. Move the 2014 posts into a 2014 folder and the 2016 post into a 2016 folder
  3. Try to compile
carmen@ouroboros [~/s/test] โ‹Š> lein ring server
loading module: Markdown parser
compiling assets...
                              java.lang.Thread.run              Thread.java:  745
java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  617
 java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1142
               java.util.concurrent.FutureTask.run          FutureTask.java:  266
                                               ...
               clojure.core/binding-conveyor-fn/fn                 core.clj: 1938
                           clojure.core/pmap/fn/fn                 core.clj: 6736
            cryogen-core.compiler/read-posts/fn/fn             compiler.clj:  151
                  cryogen-core.compiler/parse-post             compiler.clj:  131
             cryogen-core.compiler/parse-post-date             compiler.clj:   66
                        java.text.DateFormat.parse          DateFormat.java:  366
               java.text.ParseException: Unparseable date: "2014/2014-"
    errorOffset: 4
java.util.concurrent.ExecutionException: java.text.ParseException: Unparseable date: "2014/2014-"

This is because the file-name returned by page-content is 2014/2014-03-10-first-post.md and parse-post-date (used in parse-post) takes the first 10 characters of the file name to parse.


Current workaround: Add :date key to post metadata

SCSS compilation breaks watcher assumptions

When you edit scss files in the css resources directory, the watcher notices the change in sum-times and triggers a re-compile. This causes scss files to be compiled to css files in the same directory, which causes a change in sum-times, triggering another re-compile.

I'm not exactly sure how this works. I was hacking on scss.clj and noticed that it set up an infinite loop, but when I backed out again to v0.1.9 of cryogen-core, I noticed it only compiles twice per save of a SCSS file. So I'm not exactly sure of the mechanism, and specifically why it stops re-compiling at all.

There's a few possible solutions here. The watcher could switch to using checksums rather than times. The compiler could stage compiled css outside the templates directory. etc.

Schema validation for the config

Cryogen can give poor errors when the configuration is invalid. Schema or Spec should be used to validate the configuration when compiling and provide meaningful errors to the user. The configuration options can be found here.

Need changes to add Lotus theme

OK @lacarmen, I wrapped up the changes I wanted to make, and set about adding the files to cryogen. As soon as I did, though, I ran into a few issues that earlier themes don't have:

  1. My theme requires Sass, but the css dir under a theme isn't automatically run through sassc.
  2. My theme has images, in particular, a social icons SVG. copy-resources-from-theme doesn't copy the theme's img dir.

I opened this issue to get your feedback before proceeding. I see a few options, but I'm open to whatever you like:

  1. I change nothing but add a README in the theme directory, instructing people how to update the :resources and :sass-src keys to get the theme working. Simple, but a crappy experience, since people won't read it.
  2. I add img to the default list of theme directories copied, and create empty img dirs in the existing themes to prevent breaking. For Sass, I add the public css folder as a default, and reorder Sass compilation to happen after the resources are copied over.
  3. Give themes a config.edn of their own where they can add entries to the existing config to specify what they need.

I think option 3 is the most future-proof and elegant. Thoughts?

`<!--more-->` markers not respected

Hey, thanks for your work on Cryogen. ๐Ÿ˜„

I noticed that <!--more--> markers are not respected for determining preview boundaries. The :blocks-per-preview configuration is used instead, even when there's a marker present. This is true whether the marker occurs before or after the :blocks-per-preview cutoff.

I confirmed that this is present in a new, current Cryogen blog. Here's how to reproduce:

  1. lein new cryogen cryogen-blog and cd cryogen-blog
  2. Change resources/templates/config.edn so that :previews? is true.
  3. Add a <!--more--> marker in resources/templates/md/posts/2016-01-07-docs.md, e.g. just before the # Prerequisites heading.
  4. Start the server with lein ring server.
  5. Note that the previews in the index page obey the :blocks-per-preview configuration and ignore the <!--more--> marker. You can change both of these things, but the behavior is consistent.

I can see that there's a test for the cryogen-core.compiler/content-until-more-marker function, and all tests pass for me in the latest cryogen-core code. So I'm guessing the function works as expected but that either it isn't being called when it should be or it's results are being dropped somewhere along the way.

Provide an option to drop the date from file names

Having a file like content/asc/posts/2019-03-21-awesome-post.asc generates public/<posts-root-uri>/2019-03-21-awesome-post.html however I want it without the date, i.e. awesome-post.html (so that I don't break all URLs after migrating to Cryogen - and I prefer the dates in the source file name as they are nicely sorted by it).

A solution would be to add :post-remove-date true (or post-dateless-uri)?

I'd be happy to provide a PR.

Swappable templating

I prefer hiccup syntax to selmer, so I would like to be able to choose templating solutions.

Error while start ring server with cryogen-core snapshot

While I try to start the site with cryogen and cryogen-core on 'master'
I have an error
Steps:

  1. clone cryogen-core, clone cryogen
  2. rename cryogen-core to "0.1.26-SNAPSHOT" and run lein install
  3. lein new cryogen site-on-master
  4. change dependencies for project to use local version
  5. lein ring server
loading module: Markdown parser
compiling assets...
                              java.lang.Thread.run              Thread.java:  745
java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  617
 java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1142
               java.util.concurrent.FutureTask.run          FutureTask.java:  266
                                               ...                               
               clojure.core/binding-conveyor-fn/fn                 core.clj: 1916
                           clojure.core/pmap/fn/fn                 core.clj: 6729
            cryogen-core.compiler/read-posts/fn/fn             compiler.clj:  126
                  cryogen-core.compiler/parse-post             compiler.clj:  106
      cryogen-core.compiler/merge-meta-and-content             compiler.clj:   90
                                               ...                               
                     cryogen-core.toc/generate-toc                  toc.clj:  110
                                               ...                               
                        cryogen-core.toc/build-toc                  toc.clj:   80
                                 clojure.core/name                 core.clj: 1524
           java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.Named
java.util.concurrent.ExecutionException: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.Named

Support for GFM tables

With a quick look I couldn't figure out which lib is doing the markdown compiling. I'm guessing table support would be based on whether our markdown compiler supports it.

GFM Tables

Allow nested URL structure

It would be great if I could define a URL structure like mysite.com/2015/11/23/mypost. Is this possible/doable?

Relates to #56

config based themes

  • pull out hardcoded template variables into config
  • provide a way to select themes from using a config variable
  • fetch themes from github using theme name?

Modifying :post-root eliminates all posts

Create a new cryogen project and build.

With the default settings, this will generate folder blog/posts containing all posts.

If I edit config.edn to read :post-root "foo" and rebuild, no "foo" folder is created and the original "posts" folder is also gone. The posts are not generated:

$ ls blog/*
blog/404.html       blog/cryogen.xml    blog/index.html
blog/archives.html  blog/feed.xml       blog/sitemap.xml

blog/css:
asciidoc.css    screen.css

blog/js:
highlight.pack.js

blog/pages:
about.html      another-page.html

Also, the "tags" folder is missing. When I restore :post-root "posts" these things return:

$ ls blog/*
blog/404.html       blog/cryogen.xml    blog/index.html
blog/archives.html  blog/feed.xml       blog/sitemap.xml

blog/css:
asciidoc.css    screen.css

blog/js:
highlight.pack.js

blog/pages:
about.html      another-page.html

blog/posts:
10-03-2014-first-post.html  11-04-2014-second-post.html 13-11-2014-docs.html

blog/tags:
cryogen.html    not fetch.html  very fetch.html

I'm seeing the same behavior for :page-root. Thanks for your work on this project.

Provide :preview-plaintext to every post, page for SEO

Make the "preview" of a page/post available to it as plain text so that it can be included in <meta name="description" content=...> and similarly in og:description etc to show nice previews in Slack, Fb etc and provide better SEO.

I'd be happy to make a PR for this, likely using the existing html previews and extracting the plain text from them using Enlive or JSoup.

Centred blue theme inconsistency

Hi,

I was looking at the centred blue theme and noticed that when you hit the smaller media size the menu colouring all changes to black and grey instead of blue and white. I couldn't see the css item that was affecting it, so I think it's inheriting it is not getting set once the navbar goes to collapsed.

Proposal: Replace :content with :content-dom

Currently articles have their text under :content, which we parse repeatedly in create-preview and add-description.

It would be more efficient to parse the content into an enlive tree once in page-content and include it under :content-nodes (or perhaps better :content-dom ?) and use that at all the other places. Then we would emit* + str it at the very end, right before we call render-file on it.

This is a breaking change but until 0.2.1 and its extend-params-fn there was no official way to access it and even this was not primarily intended to give access to the content (contrary to the upcoming #130).

(We would ideally rewrite content-until-more-marker to use the dom instead.)

What do you think, @lacarmen ?

Overriding Config

Hey, would it be possible to do some sort of config override?

I tend to draft posts in the future and I've not figured out how to preview them for editing other than manually toggling :hide-future-posts?.

I'd much rather prefer to create a lein alias so I can just get all the drafts / future posts visible for when I'm writing.

There's a couple of ways this could be done, but the easiest is probably adding an optional arg or env var capture a path to a config here?

I'd rather not pull in new deps (unless you think it's warranted) so probably just use:

(System/getenv "CRYOGEN_CONFIG")

Which specifies a project relative path, eg, the default is: "content/config.edn" and then apply that?

How does that sound? =)...

An exception in compile-assets-timed should fail the build

compile-assets-timed shouldn't just catch + log exceptions, it should rethrow them so lein run would fail. As it is now, if the build fails, my build script cannot know it and will deploy the incomplete site, breaking my blog.

Do you agree?

image handling in Post is generally broken

First, I have a hard time when i try to include images in markdown
, when I am following the instructions from Including Images in Posts.

  1. Missing resources/public/img/xxxx.jpg

    The source of the problem is the copy-images-from-markdown-folders will never
    create the folder resources/public/img/ when it does not exist, so the io/copy will fail forever.

    (defn copy-images-from-markdown-folders [{:keys [blog-prefix]}]
      (doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
        (io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))

    Finally, I avoid this bug by creating img folder in resources/templates adding this line to config.edn

     :resources        ["css" "js" "img" "404.html"]
  2. Naming conflict for posts images

    Since all posts' image will be flatten into /img/, the images with same name will be overwritten.

  3. Not supporting all image formats which widely supported

    Bottom line, SVG should be supported by the copying function.

  4. Inconsistent image handling for Asciidoc

    As the copy-images-from-markdown-foldersfunction name implied, only images in/md/` folder will be copied. This raise the question, where should I place my post's images for Asciidoc posts?

Solution

Replace copy-images-from-markdown-folders with function

(defn copy-post-assets [config] ...)

The function will copying posts' resources like

from to
posts/goodpost/abc.png resources/public/post-assets/goodpost/abc.png
posts/anotherpost/b.gif resources/public/post-assets/anotherpost/b.gif
posts/anotherpost/a.zip resources/public/post-assets/anotherpost/a.zip

The advantages are

  • no naming conflict
  • consistent between asciidoc and markdown
  • generally apply to all file type
  • open chance to support different folder structure like /posts/2015/12/11/my-post.html
  • actually, implementation is just reuse the copy-resources function

Globally available data services in template contexts.

I'd like some way of defining data that is generated at build time and then made available to various templates. I know I can fork cryogen-core and hack something in each time, but it'd be nice to say something like

:custom-data-providers {:my-key :my-namespace/some-func}

And then be able to write a template that presumed the existence of my-key.

I'll probably hack this in for myself, but is there any interest on standardizing something like this?

Bug: cannot set a page as homepage

Attempted: adding a :home? true flag to a page.

Problem observed: page contents don't render.

Reproducible on a fresh cryogen install (screenshot attached.)

Cause:

  1. in params, :home-page may contain either a page or a post map.
  2. compile-index extracts :home-page and re-attaches it to params as both :post and :page, then passes the resulting map to render-file - see code.
  3. render-file calls htmlize-content
  4. in htmlize-content, cond short-circuits after finding :post and never htmlizes :page - see code
  5. back to compile-index - it selects the correct layout via (:layout home-page), and the layout attempts to print page.content, which has not been created in the previous step

Some options for a fix:

  • update htmlize-content to use cond-> instead of cond, and fix all available keys
  • fix compile-index so that it includes either a :post or a :page but not both (pages contain :page-index while posts don't)
  • have page and post maps contain :type :page or :type :post and have compile-index merge (:type home-page) home-page into params

homepage-about

Allow pages and posts to output to root directory

I think it would be preferable to allow the output of pages and posts to the root directory without an additional prefix like posts or pages for users who want it.

To be honest, I'm not entirely sure if this is meant to be possible with the current release of Cryogen. I didn't find mention of it in the docs, and when I tried setting the appropriate configs to empty, it ended up silently breaking the output rendering in some places. So, I'm not sure whether this should be a change to the docs or a change to the compiler.

What would need to change? How big of a change would this be? Could this be done in a backward compatible way? The configuration keys for post-root and page-root would need to be split out somehow, so that the post and page sources can live in separate directories and both output to the root directory. For backwards compatibility, my initial idea is: post-root and page-root determine input directories. If specified, post-output-root and page-output-root determine output directories. If unspecified, default to previous behavior.

I would be fine with making these changes and submitting a PR, if someone who is more familiar with the codebase could please clarify and confirm the above, as to avoid potentially going in the wrong direction with this.

Thanks!

Allow using both Asciidoc and Markdown for individual pages and posts

It would be great if it were possible to have individual posts and pages in different formats. Instead of having a choice between Markdown and Asciidoc as a config value, we can just allow both. We could then keep both Markdown and Asciidoc templates in the same directory, and determine the format either by template file extension, or by the metadata.

Change in clean-urls behaviour

With cryogen-core 0.1.61 I had clean-urls? enabled and so Cryogen generated files/URLs such as

/resources/public/posts-output/2018-10-16-arch-block-devs/index.html

After switching to 0.1.65 (following the merging of (#113) I can only generate files like the following (with clean-urls? still enabled):

/resources/public/posts-output/2018-10-16-arch-block-devs.html

However URLS in the generated HTML files are inconsistently of the following form:

/posts-output/2018-10-16-arch-block-devs

Can we reenable the 0.1.61 behaviour?

FYI my project.clj contains:

            :dependencies [[org.clojure/clojure "1.9.0"]
                           [ring/ring-devel "1.6.3"]
                           [compojure "1.6.0"]
                           [ring-server "0.5.0"]
                           [cryogen-markdown "0.1.7"]
                           [cryogen-core "0.1.65"]]
            :plugins [[lein-ring "0.12.5"]]
            :main cryogen.core
            :ring {:init cryogen.server/init
                   :handler cryogen.server/handler})

Emacs interlock files cause an error on startup

So the files ignored by default by the new :ignored-files configurable include emacs #.* files. I kind of thought these were backup/autosave files, but they aren't, they're interlock files. These are special files, and apparently they can't be stated.

If such a file exists (for example, if you're editing a template and haven't saved it yet) when you start up the watcher, it barfs with an error which looks like this:

Error: /Users/joni/Scratch/clojure/radiculopath/resources/templates/css/.#screen.scss not found

This turns out to be me.raynes.fs/exists? failing to stat the file when attempting a me.raynes.fs/copy-dir as part of cryogen-core.io/copy-resources.

Though the :ignored-files patch prevents the creation of interlock files from triggering a compilation, the pre-existence of such files opens up this bug - and I imagine that you could trigger it by editing a couple of files within the templates directory and then saving one of them leaving the other interlock in place.

Right now I don't see a way to deal with this other than re-writing the compiler to copy individual files rather than directories. Definitely I see no way to tell me.raynes.fs to deal with interlock files differently.

This is clearly an edge case and it's perfectly possible to work around it, but I'm reporting it to get it bookmarked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.