GithubHelp home page GithubHelp logo

lerni / silverstripe-sitetreeimporter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silverstripe-archive/silverstripe-sitetreeimporter

0.0 3.0 0.0 36 KB

SilverStripe SiteTree Importer Module

PHP 100.00%

silverstripe-sitetreeimporter's Introduction

Site Tree Importer Module

Build Status

Requirements

  • SilverStripe 4 or later

Installation

No installation required.

Usage

Make a tabbed-out file as directed in the form that appears below. Make sure that you use tabs, not spaces. Visit http://localhost/your-site-name/SiteTreeImporter?flush=1. Select your tabbed-out file in the file field, and tick the option boxes as appropriate:

Clear out all existing content? - This will delete everything from your site before running the importer. Use with caution! If you don't tick this, then the pages will be added to the existing site.

Publish everything after the import? - This will publish each of the pages that the importer creates. If you don't tick this, then the pages will be left as draft-only.

Format

The site tree import module lets you take a tabbed out file of the following format, and load it into your CMS as a site tree.

Home
About
	Staff
		Sam
		Sig
Products
	Laptops
		Macbook
		Macbook Pro
	Phones
		iPhone

You can optionally include JSON encoded metadata as the last part of a line, which will automatically save to properties on the Page object. This can be useful to determine URL paths or set custom titles.

Home
	About {"URLSegment": "about-us", "MetaDescription": "About our company"}
	Contact {"URLSegment": "contact-us"}

Howto

Redirect URLs

Often an existing tree will need to be imported with URLs which map to different URLs on the new site. While you could assign those manually to a .htaccess based redirect, we found it useful to store the old URL straight in the Page object, and use SilverStripe's routing to handle the redirect.

In this example, we'll use the "redirected urls" module, which routes based on a new data type called RedirectedURL. In order to create it, we add a custom setter to the Page class, which gets called automatically if a key named LegacyURL is found in the imported JSON data.

class Page extends SiteTree {
	public function setLegacyURL($url) {
		$url = Director::makeRelative($url);
		$urlBase = parse_url($url, PHP_URL_PATH);
		$urlQuerystring = parse_url($url, PHP_URL_QUERY);

		$urlObj = RedirectedURL::get()->filter(array(
			'FromBase' => $urlBase,
			'FromQuerystring' => $urlQuerystring
		))->First();
		if(!$urlObj) {
			 $urlObj = new RedirectedURL();
		}
		$urlObj->FromBase = $urlBase;
		$urlObj->FromQuerystring = $urlQuerystring;

		if(!$this->URLSegment) {
			$this->URLSegment = $this->generateURLSegment($this->Title);
		}
		$urlObj->To = $this->RelativeLink();

		$urlObj->write();
	}
}

Now you can import a tree based on the following data:

Home
	About {"LegacyURL": "/old-about-location"}
	Contact {"LegacyURL": "/old-contact-location"}

Related

See the static site connector module for a more sophisticated importer based on crawling existing HTML pages, and extracting content via XPATH.

silverstripe-sitetreeimporter's People

Contributors

adiwidjaja avatar chillu avatar dhensby avatar jellygnite avatar lerni avatar mateusz avatar

Watchers

 avatar  avatar  avatar

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.