Giter Club home page Giter Club logo

Comments (9)

benjamincanac avatar benjamincanac commented on August 15, 2024 9

Hey @janekkkk,

Nuxt Content parses markdown files on the file system on load and builds an API around the database generated from the content directory, it cannot be used on eternal sources.

You're alternative seems the way to go.

from content.

sillvva avatar sillvva commented on August 15, 2024 7

I also would like to be able to host my markdown files in Firebase Cloud Storage and fetch them at runtime via an API. I already figured out hot to dynamically generate the routes. The only thing I haven't figured out is how to parse the markdown into the tag. Some of my markdown files have vue components in them, so a 3rd party API isn't a feasible option for me.

from content.

txhai avatar txhai commented on August 15, 2024 4

I am still looking for this. It would be great if I can host and update my blog posts on a Github repository, instead of rebuilding the entire Nuxt project.

from content.

cschweda avatar cschweda commented on August 15, 2024 3

An easy solution to this is to simply fetch the external markdown files in a node script that runs before the build/export steps.
Fetch (or use axios or whatever) the files, save them in the content directory, and then npm run build/export everything from there.
I do this -- and it seems to work (in my case, at least). I'm building on Netlify. No issues with this approach.

That's really interesting — if your external database updates (e.g. you have a new blog), how does that trigger Netlify to re-run the fetch script to build that new file into content directory, and then rebuild/re-export the Nuxt site?

I use Strapi as an external API/auth service -- but the way I've dealt with this sort of issue with Strapi is to send a build hook when the user adds new content and then updates a "build" task.

My use case for this is when new content is added or updated -- I ask users to insert a new build task (a content-type in Strapi). When they enter the new task -- a note and their initials -- Strapi sends a webhook to Netlify to initiate a build. I have a node file that runs as part of the build to update the search index. This node script generates an index for the entire site (including the new content item(s)) -- and then rebuilds everything. (I use fuse.js for the search.)

This approach works great -- no issues. The only thing I need to watch are my Netlify build minutes (about 60 seconds for each site) -- but I'm managing about 15 sites this way on Netlify without issues. (These are low-traffic but critical sites -- so that's why Netlify is perfect.)

from content.

ninest avatar ninest commented on August 15, 2024 2

I know the issue is closed, but I also wish there was a better way to use Nuxt Content's markdown features for external files. One solution is to use hmsk/frontmatter-markdown-loader, but I wish there was a way to do it using only Nuxt Content

from content.

cschweda avatar cschweda commented on August 15, 2024

An easy solution to this is to simply fetch the external markdown files in a node script that runs before the build/export steps.

Fetch (or use axios or whatever) the files, save them in the content directory, and then npm run build/export everything from there.

I do this -- and it seems to work (in my case, at least). I'm building on Netlify. No issues with this approach.

from content.

janzheng avatar janzheng commented on August 15, 2024

An easy solution to this is to simply fetch the external markdown files in a node script that runs before the build/export steps.

Fetch (or use axios or whatever) the files, save them in the content directory, and then npm run build/export everything from there.

I do this -- and it seems to work (in my case, at least). I'm building on Netlify. No issues with this approach.

That's really interesting — if your external database updates (e.g. you have a new blog), how does that trigger Netlify to re-run the fetch script to build that new file into content directory, and then rebuild/re-export the Nuxt site?

from content.

janzheng avatar janzheng commented on August 15, 2024

I know the issue is closed, but I also wish there was a better way to use Nuxt Content's markdown features for external files. One solution is to use hmsk/frontmatter-markdown-loader, but I wish there was a way to do it using only Nuxt Content

Here's a quick example of how to load and build the /content folder for Nuxt. This script runs independently of Nuxt, but can be added to the dev or build process as a script in package.json.

  1. Create a loadContent.js script in your folder

const fetch = require("node-fetch");
const fs = require('fs');

console.log('>>> Loading External Content')

let url = 'https://your-url/api/content'
let path = './content/testfile.js'

const downloadFile = (async (url, path) => {
  const res = await fetch(url);
  const fileStream = fs.createWriteStream(path);
  await new Promise((resolve, reject) => {
    res.body.pipe(fileStream);
    res.body.on("error", (err) => {
      reject(err);
    });
    fileStream.on("finish", function() {
      resolve();
    });
  });
});

downloadFile(url,path)
  1. In package.json create a script:
 "scripts": {
    ...
    "loadContent": "node helpers/loadContent.js",
    ...
  1. In console, run npm run loadContent to load the files
  2. To add to the build script, change the build script to
   "build": "npm run loadContent; nuxt build",

I don't add the content loader to the dev because my loader takes a while

Hope that helps!

from content.

goodpixels avatar goodpixels commented on August 15, 2024

Are you using a webook or a server hook? Would you be able to share some code if you don't mind please?

from content.

Related Issues (20)

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.