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

[How to] Generate title with another fields #1

Open
Toutenkit opened this issue Sep 17, 2021 · 2 comments
Open

[How to] Generate title with another fields #1

Toutenkit opened this issue Sep 17, 2021 · 2 comments

Comments

@Toutenkit
Copy link

Hi,

On the ligne 14, create a title
https://github.com/chrisullyott/csv-to-grav/blob/master/convert.php#L14

How to generate title with another fields
Exemple

$title = 'name_field' . ' ' . 'surname_field';
$conversion->setColumnMap(array(
    // 'title'    => 'title_field',    // string
    'title'    => $title,    // string
    'date'     => 'date_field',     // string
    'html'     => 'html_field',     // string
    'author'   => 'author_field',   // string
    'category' => 'category_field', // comma-separated list
    'tag'      => 'tag_field',       // comma-separated list
    'name' => 'name_field',
    'surname' => 'surname_field'
));

Kind regards
Kit

@Toutenkit
Copy link
Author

Found it 😃
Before line 24
Add
$this->title = $this->name. ' ' . $this->surname;

csv-to-grav/src/Post.php

Lines 22 to 34 in eb41b7c

private function provision()
{
$this->slug = slugifier\slugify($this->title);
$this->date = date(self::$dateFormat, strtotime($this->date));
$categories = self::explodeList($this->category);
$this->category = strtolower($categories[0]);
$tags = self::explodeList($this->tag);
$this->tag = array_map('strtolower', $tags);
return $this;
}

And comment

Kind regards
Kit

@bonnebulle
Copy link

bonnebulle commented Mar 7, 2024

EDIT :
yes, easy to add fields
For noobs, some instructions :
In CsvToGrav.php
into private static add your fields
ex/ date_deb

In Post.php
into private function provision() add your field like
$date_deb = self::explodeList($this->date_deb);
into private function getHeaders() insert yours
'date_deb' => $this->date_deb,
(etc.)


Hey
I cant figure how to map more data from my csv file
Maybe you can help me ?
Like you can see we have a lot of fields ...

// Set the column map (Grav -> CSV).
$conversion->setColumnMap(array(
    'title'         => 'post_title',    // string
    'date'          => 'post_date',     // string
    'html'          => 'post_content',    // string
    'author'        => 'author_name',    // string
    'category'      => 'post_category', // comma-separated list
    'tag'           => 'tag',       // comma-separated list
    'text_intro'    => 'texte-intro',     // string
    'sur_titre'     => 'sur-titre',    // string
    'slug'          => 'post_name',    // string
    'cover_url'     => 'cover_url',    // string
    'cover_name'    => 'cover_name',    // string
    'artist'        => 'artiste',     // string
    'color'         => 'c-border',    // string
    'date_deb'      => 'date_deb',     // string
    'date_deb_time' => 'date_deb_time',     // string
    'date_fin'      => 'date-fin',     // string
    'date_fin_time' => 'date_fin_time',     // string
    'status'        => 'post_status',    // string
    'post_id'       => 'post_id',    // string
    'fb_link_1'     => 'fb_link',   // string
    'fb_link_2'     => 'fb_link2',   // string
    'fb_link_3'     => 'fb_link3',   // string
    'copyrights'    => 'copyrights'     // string
));

but, after php convert.php

  • published
  • title
  • slug
  • date
  • author
  • category
  • tag
    are exported :(
    I think this not included in Csv-to-grav
    (to automatically import extra fields)

I will try to improve it following your instructions here (past)
Thanks

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

No branches or pull requests

2 participants