Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable content slides on homepage, how? #227

Open
sandrodz opened this issue Feb 23, 2016 · 5 comments
Open

variable content slides on homepage, how? #227

sandrodz opened this issue Feb 23, 2016 · 5 comments
Labels

Comments

@sandrodz
Copy link

@sandrodz sandrodz commented Feb 23, 2016

How would you implement something like this in metalsmith?

Problem 1:
I've N amount of slides on homepage. Each slide can contain N amount of Posts.
I want to manually control N amount of slides, and posts that are displayed there.

Problem 2:
Post featured image.

@Ajedi32 Ajedi32 added the question label Feb 23, 2016
@Ajedi32
Copy link
Collaborator

@Ajedi32 Ajedi32 commented Feb 23, 2016

It sounds to me like you're imagining Metalsmith to be a much higher-level library than it is. Metalsmith isn't a UI framework; it's a static site generator.

You implement a carousel in Metalsmith the same way you would on any website: by writing the necessary HTML/CSS/JavaScript yourself, or by using an existing library that does it for you. (Slick was the first example of such a library that appeared when I Googled it.)

@sandrodz
Copy link
Author

@sandrodz sandrodz commented Feb 23, 2016

Hey, thanks for the reply but that is not what im asking. I aleeady have frontend, im using metalsmith as "backend" if it can be called that :) simplest solution that comes to mind is creating a custom object with parameter link / title / thumb than loop over it in tempkate file and display my slider, but there surely is a better way right?

@Ajedi32
Copy link
Collaborator

@Ajedi32 Ajedi32 commented Feb 23, 2016

I'm still not quite sure what you're asking. What plugins are you currently using? metalsmith-collections should allow accessing a list of "posts" through the global metadata if that's what you're looking for...

@sandrodz
Copy link
Author

@sandrodz sandrodz commented Feb 23, 2016

I'm using quite a lot of plugins actually, including collections.

var Metalsmith  = require('metalsmith');
var templates   = require('metalsmith-react-templates');
var assets      = require('metalsmith-assets');
var markdown    = require('metalsmith-markdown');
var publish     = require('metalsmith-publish');
var collections = require('metalsmith-collections');
var ignore      = require('metalsmith-ignore');
var permalinks  = require('metalsmith-permalinks');
var paths       = require('metalsmith-paths');
var serve       = require('metalsmith-serve');
//var watch       = require('metalsmith-watch');

Metalsmith(__dirname)
  .source('content')
  .destination('build')
  .clean(true)
  .use(ignore([
    'articles/.*',
    'projects/.*'
  ]))
  .use(publish())
  .use(collections({
    pages: '*.md',
    articles: {
      pattern: 'articles/*.md',
      sortBy: 'date',
      reverse: true
    },
    projects: 'projects/**/*.md'
  }))
  .use(markdown())
  .use(permalinks())
  .use(paths({
    property: "paths"
  }))
  .use(templates({
    directory: 'templates',
    isStatic: true
  }))
  .use(assets({
    source: 'public'
  }))
  .use(serve())
  //.use(watch({
  //  paths: {
  //    "${source}/**/*": "**/*",
  //    "templates/**/*": "**/*"
  //  },
  //  livereload: false
  //}))
  .build(function(err) {
    if (err) throw err;
  });

I want to display articles and projects on my slider.

slide1:article1,article2,project6
slide2:project1,project2,project5,article3

What I would do in say laravel/RoR is to create a table (Entity–attribute–value model) with col1=key/col2=value combination, key would be a slide name/order, and value would be a serialised list of article ids. Than in template I'd run foreach on those and display slides with attached articles.

back to metalsmith.
I could simply put following object in my homepage.yml (and loop over it in template):

{slide1: [{article1: url, title, other_meta},{article2: url, title, other_meta},{project1: url, title, other_meta}]}

but this seems tedious, and I don't want to keep track of each article url, or title, I want them to come from article.md files themselves.

So I've following issues:

  1. where/how to save my data associations {slide1: [article1,article2,project6]}
  2. how to 'query' for article1 article2 project6 so I don't have to hardcode links / titles etc.

this is the best I can do. sorry if my explanation is not great.

@Ajedi32
Copy link
Collaborator

@Ajedi32 Ajedi32 commented Feb 26, 2016

This sounds like something you may want to use a custom plugin for. You can "query" for projects by accessing the projects attribute in the global metadata, then programmatically build your slides object from that.

Here's an article on writing plugins for Metalsmith. If you're already familiar with JavaScript the process is actually pretty straightforward: http://www.andrewgoodricke.com/blog/metalsmith-plugins/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.