I'm writing a Rake task to automatically update my Jekyll site, based on the response from an external API. For example, the API may return a list of posts and I would create files in the _posts directory for any new content.
Every post has an ID, and that's what I use to determine if it's been previously published or not.
My question: how can I access the site object from within my Rake task (i.e. external to the running Jekyll environment) in order to access the id frontmatter in each post's header?
Note: I'd like to avoid parsing files myself, and would really like to use Jekyll to do that, if possible.
EDIT: Pretty sure this would involve require Jekyll::... but I'm unsure what needs to be included to allow access to the site variable
Related
I'm integration nuxtjs/content (https://content.nuxtjs.org/writing) for my contents. But I would like to have the json file generated from responses from my API.
How I can create a command to retrieve, maybe thought cron, the contents and save it in content/ folder?
You could indeed, depending of your hosting solution, have something running every midnight and rebuilding your app. Where you could run some Node.js script to create files in the given directories before it is handled by nuxt/content.
An example of code can be found here: https://stackoverflow.com/a/67689890/8816585
Using Liquid, I am trying to build a JSON object (skills.json) containing data from all of my Jekyll posts.
When I place this file in my _data folder in my project root directory per https://jekyllrb.com/docs/datafiles/, trying to access the data via site.data.skills with the inspect filter or console log resolves to nothing.
final output section of my Liquid json
When I instead place my skills.json file in the /assets/js/ folder in my root, I do see that the properly populated JSON file is added to my _site folder as expected. Copying this NEW file into the root _data folder successfully populates to my page as intended, and I am able to access all the data with site.data.skills.KEY.
json generated from assets folder at build time
Is there any way that I could specify that the generated skills.json in my /assets/js/ folder be the source for my data call?
Alternatively, is there a way to generate the final data and automatically move it to the _data folder ahead of building the site? I am open to any suggestions for how to automate this. As a warning, I am pretty new to web development in general, so any references or links would be a tremendous help. Thanks!
Following up on this, I believe that the issue lies in how the site is built. The skills.json file gets generated on the first build, and then when it is added to the _data folder, the site gets built AGAIN to update everything that hits that data. With this iterative process, I don't know if it would be possible to both generate the new file and use it as a source to update everything dependent on the data in the same pass.
As far as automating goes, my thinking is that a Ruby plugin to compare the newly generated files against the _data folder and overwrite if the source is different/newer would be the way to go, but I'm still open to any suggestions!
I have been trying to find what a db.json is and why it is being automatically genereated. All the documentation says in hexo.io is:
$ hexo clean
Cleans the cache file (db.json) and generated files (public).
What is this exactly? Since these are all static pages, is this some sort of makeshift database?
most commonly db.json is used when you're running a server using hexo server. I believe its for performance improvements. It doesn't affect the generation (hexo generate) and deployments(hexo deploy)
db.json file stores all the data needed to generate your site. There are all posts post, tags, categories etc. The data is stored in a JSON formatted string so it's easier and faster to parse the data and generate the site.
I would like to generate a bunch of static pages with my rails app, which then will be stored to the filesystem in order to be part of a build step in a yeoman webapp.
The filetypes would be JSON and HMTL.
Therefore I would like to know what would be the best solution for this problem. Fetching the site with Nokogiri or something similar, transform it to string and put it into a file. Or maybe write a rake task, which starts curl which then puts it into a file.
Or is there something build-in which can handle this type of problem?
Update:
I guess I have to make my goal clearer: I would like to build a website generator, which can export webpages and json to the local file system. In order to get fast response times and to use my existing build process I would like to generate those files and not serve them via rails.
Not sure what you're trying to do, but you might consider something like middleman. It's meant to generate static files, but you can still do ruby/rails like magic, etc.
http://middlemanapp.com/
This is my first time working with Django and while I'm finding the tutorial they provide to be very helpful, there is one major issue I'm having moving forward with my project.
The most confusing aspect of Django so far is the layout of files in a project. As of now, the layout of my project is as follows:
webapp/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
app/
__init__.py
models.py
tests.py
views.py
Bear with my naming here, I created a Django project "mysite" and an app "app". Here are the questions I find myself continually returning to:
I've noticed that in mysite/settings.py there is a section for apps, would I include the app I'm writing in this project in that section once I've finished it?
If I were to want to create a simple index.html page, where would a file like that go in this project organization?
I've read that static content like CSS or image files need to be contained within a simple "static" directory. Where would this go in this project organization? [ This would be for debugging purposes only, I've read this should never be done for production ]
My main goal right now is to just be able to view a simple html site before I begin delving into the models and views of the app I'm creating.
If your app needs one or more setting variables, then yes, you would put those in mysite/settings.py
Create a new folder mysite/templates/. This is where you want to put your template files. Organize your templates per app: mysite/templates/app/ would have the templates used by your app views. If you want to serve static templates such as a simple static index.html, then just throw that file in mysite/templates/index.html and then add the following to your urls.py file (no need to create a view for the index):
(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}),
Static content would end up in something like mysite/static after you run the collectstatic command. See managing static files. The collectstatic command searches for static files in all locations specified in STATICFILES_DIRS and deploys them into the folder specified in STATIC_ROOT (mysite/static).